~rpadovani/oxide/type-info

« back to all changes in this revision

Viewing changes to shared/browser/oxide_user_script_master.cc

  • Committer: Riccardo Padovani
  • Date: 2015-10-19 07:56:29 UTC
  • mfrom: (1088.1.131 oxide)
  • Revision ID: riccardo@rpadovani.com-20151019075629-z0mlhwlb9xflkovw
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
 
// Copyright (C) 2013 Canonical Ltd.
 
2
// Copyright (C) 2013-2015 Canonical Ltd.
3
3
 
4
4
// This library is free software; you can redistribute it and/or
5
5
// modify it under the terms of the GNU Lesser General Public
27
27
#include "base/strings/string_util.h"
28
28
#include "components/keyed_service/content/browser_context_dependency_manager.h"
29
29
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
30
 
#include "content/public/browser/notification_service.h"
31
 
#include "content/public/browser/notification_types.h"
32
30
#include "content/public/browser/render_process_host.h"
33
31
#include "extensions/common/url_pattern.h"
34
32
 
52
50
  std::string temp(line.data() + index + prefix.length(),
53
51
                   line.length() - index - prefix.length());
54
52
 
55
 
  if (temp.empty() || !IsWhitespace(temp[0])) {
 
53
  if (temp.empty() || !base::IsUnicodeWhitespace(temp[0])) {
56
54
    return false;
57
55
  }
58
56
 
68
66
  static UserScriptMaster* GetForContext(content::BrowserContext* context);
69
67
 
70
68
 private:
71
 
  friend struct DefaultSingletonTraits<UserScriptMasterFactory>;
 
69
  friend struct base::DefaultSingletonTraits<UserScriptMasterFactory>;
72
70
 
73
71
  UserScriptMasterFactory();
74
72
  ~UserScriptMasterFactory() override;
101
99
 
102
100
// static
103
101
UserScriptMasterFactory* UserScriptMasterFactory::GetInstance() {
104
 
  return Singleton<UserScriptMasterFactory>::get();
 
102
  return base::Singleton<UserScriptMasterFactory>::get();
105
103
}
106
104
 
107
105
// static
113
111
 
114
112
 
115
113
UserScriptMaster::UserScriptMaster(BrowserContext* context) :
116
 
    context_(context) {
117
 
  registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
118
 
                 content::NotificationService::AllBrowserContextsAndSources());
119
 
}
 
114
    context_(context) {}
120
115
 
121
116
UserScriptMaster::~UserScriptMaster() {}
122
117
 
 
118
UserScriptMaster::HostSet UserScriptMaster::GetHostSet() const {
 
119
  HostSet hosts;
 
120
 
 
121
  for (content::RenderProcessHost::iterator it =
 
122
          content::RenderProcessHost::AllHostsIterator();
 
123
       !it.IsAtEnd(); it.Advance()) {
 
124
    content::RenderProcessHost* host = it.GetCurrentValue();
 
125
    BrowserContext* other =
 
126
        BrowserContext::FromContent(host->GetBrowserContext());
 
127
    if (context_->IsSameContext(other)) {
 
128
      hosts.insert(host);
 
129
    }
 
130
  }
 
131
 
 
132
  return hosts;
 
133
 
 
134
}
 
135
 
123
136
void UserScriptMaster::SendUpdate(content::RenderProcessHost* process) {
124
137
  if (!shmem_) {
125
138
    return;
140
153
  }
141
154
}
142
155
 
143
 
void UserScriptMaster::Observe(
144
 
    int type,
145
 
    const content::NotificationSource& source,
146
 
    const content::NotificationDetails& details) {
147
 
  if (type != content::NOTIFICATION_RENDERER_PROCESS_CREATED) {
148
 
    return;
149
 
  }
150
 
 
151
 
  content::RenderProcessHost* process =
152
 
      content::Source<content::RenderProcessHost>(source).ptr();
153
 
  if (!context_->IsSameContext(
154
 
      BrowserContext::FromContent(process->GetBrowserContext()))) {
155
 
    return;
156
 
  }
157
 
 
158
 
  SendUpdate(process);
159
 
}
160
 
 
161
156
// static
162
157
UserScriptMaster* UserScriptMaster::Get(content::BrowserContext* context) {
163
158
  return UserScriptMasterFactory::GetForContext(context);
181
176
 
182
177
  memcpy(shmem_->memory(), pickle.data(), pickle.size());
183
178
 
184
 
  for (content::RenderProcessHost::iterator it =
185
 
           content::RenderProcessHost::AllHostsIterator();
186
 
       !it.IsAtEnd(); it.Advance()) {
187
 
    content::RenderProcessHost* process = it.GetCurrentValue();
188
 
 
189
 
    if (!context_->IsSameContext(
190
 
        BrowserContext::FromContent(process->GetBrowserContext()))) {
191
 
      continue;
192
 
    }
193
 
 
194
 
    SendUpdate(process);
 
179
  HostSet hosts = GetHostSet();
 
180
  for (auto host : hosts) {
 
181
    SendUpdate(host);
195
182
  }
196
183
}
197
184
 
229
216
 
230
217
      std::string value;
231
218
      if (GetValue(line, kIncludeDeclaration, &value)) {
232
 
        ReplaceSubstringsAfterOffset(&value, 0, "\\", "\\\\");
233
 
        ReplaceSubstringsAfterOffset(&value, 0, "?", "\\?");
 
219
        base::ReplaceSubstringsAfterOffset(&value, 0, "\\", "\\\\");
 
220
        base::ReplaceSubstringsAfterOffset(&value, 0, "?", "\\?");
234
221
        script->add_include_glob(value);
235
222
      } else if (GetValue(line, kExcludeDeclaration, &value)) {
236
 
        ReplaceSubstringsAfterOffset(&value, 0, "\\", "\\\\");
237
 
        ReplaceSubstringsAfterOffset(&value, 0, "?", "\\?");
 
223
        base::ReplaceSubstringsAfterOffset(&value, 0, "\\", "\\\\");
 
224
        base::ReplaceSubstringsAfterOffset(&value, 0, "?", "\\?");
238
225
        script->add_exclude_glob(value);
239
226
      } else if (GetValue(line, kMatchDeclaration, &value)) {
240
227
        URLPattern pattern(URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS);
261
248
  }
262
249
}
263
250
 
 
251
void UserScriptMaster::RenderProcessCreated(
 
252
    content::RenderProcessHost* process) {
 
253
  SendUpdate(process);
 
254
}
 
255
 
264
256
} // namespace oxide