Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 8542001: Insert default stylesheet for platform apps. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Roll batch into ExtensionMsg_Loaded. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/extensions/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/child_process_logging.h" 8 #include "chrome/common/child_process_logging.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/renderer/extensions/file_browser_private_bindings.h" 22 #include "chrome/renderer/extensions/file_browser_private_bindings.h"
23 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 23 #include "chrome/renderer/extensions/renderer_extension_bindings.h"
24 #include "chrome/renderer/extensions/user_script_slave.h" 24 #include "chrome/renderer/extensions/user_script_slave.h"
25 #include "content/public/renderer/render_thread.h" 25 #include "content/public/renderer/render_thread.h"
26 #include "grit/renderer_resources.h" 26 #include "grit/renderer_resources.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
33 #include "ui/base/resource/resource_bundle.h"
32 #include "v8/include/v8.h" 34 #include "v8/include/v8.h"
33 35
34 namespace { 36 namespace {
35 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; 37 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
36 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; 38 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
37 } 39 }
38 40
39 using WebKit::WebDataSource; 41 using WebKit::WebDataSource;
40 using WebKit::WebFrame; 42 using WebKit::WebFrame;
41 using WebKit::WebSecurityPolicy; 43 using WebKit::WebSecurityPolicy;
42 using WebKit::WebString; 44 using WebKit::WebString;
45 using WebKit::WebVector;
46 using WebKit::WebView;
43 using content::RenderThread; 47 using content::RenderThread;
44 48
45 ExtensionDispatcher::ExtensionDispatcher() 49 ExtensionDispatcher::ExtensionDispatcher()
46 : is_webkit_initialized_(false), 50 : is_webkit_initialized_(false),
47 webrequest_adblock_(false), 51 webrequest_adblock_(false),
48 webrequest_adblock_plus_(false), 52 webrequest_adblock_plus_(false),
49 webrequest_other_(false) { 53 webrequest_other_(false) {
50 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 54 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
51 is_extension_process_ = 55 is_extension_process_ =
52 command_line.HasSwitch(switches::kExtensionProcess) || 56 command_line.HasSwitch(switches::kExtensionProcess) ||
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 175
172 void ExtensionDispatcher::OnDeliverMessage(int target_port_id, 176 void ExtensionDispatcher::OnDeliverMessage(int target_port_id,
173 const std::string& message) { 177 const std::string& message) {
174 RendererExtensionBindings::DeliverMessage( 178 RendererExtensionBindings::DeliverMessage(
175 v8_context_set_.GetAll(), 179 v8_context_set_.GetAll(),
176 target_port_id, 180 target_port_id,
177 message, 181 message,
178 NULL); // All render views. 182 NULL); // All render views.
179 } 183 }
180 184
181 void ExtensionDispatcher::OnLoaded(const ExtensionMsg_Loaded_Params& params) { 185 void ExtensionDispatcher::OnLoaded(
182 scoped_refptr<const Extension> extension(params.ConvertToExtension()); 186 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) {
183 if (!extension) { 187 std::vector<WebString> temp_patterns;
184 // This can happen if extension parsing fails for any reason. One reason 188
185 // this can legitimately happen is if the 189 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i;
186 // --enable-experimental-extension-apis changes at runtime, which happens 190 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) {
187 // during browser tests. Existing renderers won't know about the change. 191 scoped_refptr<const Extension> extension(i->ConvertToExtension());
188 return; 192 if (!extension) {
193 // This can happen if extension parsing fails for any reason. One reason
194 // this can legitimately happen is if the
195 // --enable-experimental-extension-apis changes at runtime, which happens
196 // during browser tests. Existing renderers won't know about the change.
197 continue;
198 }
199
200 extensions_.Insert(extension);
201
202 if (extension->is_platform_app()) {
203 temp_patterns.push_back(
204 WebString::fromUTF8(extension->url().spec() + "*"));
205 }
189 } 206 }
190 207
191 extensions_.Insert(extension); 208 if (!temp_patterns.empty()) {
209 // We have collected a set of platform-app extensions, so let's tell WebKit
210 // about them so that it can provide a default stylesheet for them.
211 //
212 // TODO: consider enhancing WebView to allow removing single stylesheets,
Aaron Boodman 2011/11/14 22:48:07 The convention is TODO(<whoever knows the most abo
miket_OOO 2011/11/14 23:48:51 Done.
213 // or else to edit the pattern set associated with one.
214 WebVector<WebString> patterns;
215 patterns.assign(temp_patterns);
216 WebView::addUserStyleSheet(
217 WebString::fromUTF8(ResourceBundle::GetSharedInstance().
218 GetRawDataResource(IDR_PLATFORM_APP_CSS)),
219 patterns,
220 WebView::UserContentInjectInAllFrames,
221 WebView::UserStyleInjectInExistingDocuments);
222 }
192 } 223 }
193 224
194 void ExtensionDispatcher::OnUnloaded(const std::string& id) { 225 void ExtensionDispatcher::OnUnloaded(const std::string& id) {
195 extensions_.Remove(id); 226 extensions_.Remove(id);
196 // If the extension is later reloaded with a different set of permissions, 227 // If the extension is later reloaded with a different set of permissions,
197 // we'd like it to get a new isolated world ID, so that it can pick up the 228 // we'd like it to get a new isolated world ID, so that it can pick up the
198 // changed origin whitelist. 229 // changed origin whitelist.
199 user_script_slave_->RemoveIsolatedWorld(id); 230 user_script_slave_->RemoveIsolatedWorld(id);
231
232 // We don't do anything with existing platform-app stylesheets. They will
233 // stay resident, but the URL pattern corresponding to the unloaded
234 // extension's URL just won't match anything anymore.
200 } 235 }
201 236
202 void ExtensionDispatcher::OnSetScriptingWhitelist( 237 void ExtensionDispatcher::OnSetScriptingWhitelist(
203 const Extension::ScriptingWhitelist& extension_ids) { 238 const Extension::ScriptingWhitelist& extension_ids) {
204 Extension::SetScriptingWhitelist(extension_ids); 239 Extension::SetScriptingWhitelist(extension_ids);
205 } 240 }
206 241
207 bool ExtensionDispatcher::IsApplicationActive( 242 bool ExtensionDispatcher::IsApplicationActive(
208 const std::string& extension_id) const { 243 const std::string& extension_id) const {
209 return active_application_ids_.find(extension_id) != 244 return active_application_ids_.find(extension_id) !=
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 442
408 RenderThread::Get()->RegisterExtension(extension); 443 RenderThread::Get()->RegisterExtension(extension);
409 } 444 }
410 445
411 void ExtensionDispatcher::OnUsingWebRequestAPI( 446 void ExtensionDispatcher::OnUsingWebRequestAPI(
412 bool adblock, bool adblock_plus, bool other) { 447 bool adblock, bool adblock_plus, bool other) {
413 webrequest_adblock_ = adblock; 448 webrequest_adblock_ = adblock;
414 webrequest_adblock_plus_ = adblock_plus; 449 webrequest_adblock_plus_ = adblock_plus;
415 webrequest_other_ = other; 450 webrequest_other_ = other;
416 } 451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698