1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2013 Canonical Ltd.
2
// Copyright (C) 2013-2015 Canonical Ltd.
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"
52
50
std::string temp(line.data() + index + prefix.length(),
53
51
line.length() - index - prefix.length());
55
if (temp.empty() || !IsWhitespace(temp[0])) {
53
if (temp.empty() || !base::IsUnicodeWhitespace(temp[0])) {
68
66
static UserScriptMaster* GetForContext(content::BrowserContext* context);
71
friend struct DefaultSingletonTraits<UserScriptMasterFactory>;
69
friend struct base::DefaultSingletonTraits<UserScriptMasterFactory>;
73
71
UserScriptMasterFactory();
74
72
~UserScriptMasterFactory() override;
115
113
UserScriptMaster::UserScriptMaster(BrowserContext* context) :
117
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
118
content::NotificationService::AllBrowserContextsAndSources());
121
116
UserScriptMaster::~UserScriptMaster() {}
118
UserScriptMaster::HostSet UserScriptMaster::GetHostSet() const {
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)) {
123
136
void UserScriptMaster::SendUpdate(content::RenderProcessHost* process) {
143
void UserScriptMaster::Observe(
145
const content::NotificationSource& source,
146
const content::NotificationDetails& details) {
147
if (type != content::NOTIFICATION_RENDERER_PROCESS_CREATED) {
151
content::RenderProcessHost* process =
152
content::Source<content::RenderProcessHost>(source).ptr();
153
if (!context_->IsSameContext(
154
BrowserContext::FromContent(process->GetBrowserContext()))) {
162
157
UserScriptMaster* UserScriptMaster::Get(content::BrowserContext* context) {
163
158
return UserScriptMasterFactory::GetForContext(context);
182
177
memcpy(shmem_->memory(), pickle.data(), pickle.size());
184
for (content::RenderProcessHost::iterator it =
185
content::RenderProcessHost::AllHostsIterator();
186
!it.IsAtEnd(); it.Advance()) {
187
content::RenderProcessHost* process = it.GetCurrentValue();
189
if (!context_->IsSameContext(
190
BrowserContext::FromContent(process->GetBrowserContext()))) {
179
HostSet hosts = GetHostSet();
180
for (auto host : hosts) {
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);