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

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

Issue 7517001: Switch from WebDocument::insertStyleText to ::insertUserStyleSheet for programatic CSS injection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebaseline Created 9 years, 4 months 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/user_script_idle_scheduler.h" 5 #include "chrome/renderer/extensions/user_script_idle_scheduler.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/common/extensions/extension_error_utils.h" 8 #include "chrome/common/extensions/extension_error_utils.h"
9 #include "chrome/common/extensions/extension_messages.h" 9 #include "chrome/common/extensions/extension_messages.h"
10 #include "chrome/renderer/extensions/extension_dispatcher.h" 10 #include "chrome/renderer/extensions/extension_dispatcher.h"
11 #include "chrome/renderer/extensions/extension_groups.h" 11 #include "chrome/renderer/extensions/extension_groups.h"
12 #include "chrome/renderer/extensions/extension_helper.h" 12 #include "chrome/renderer/extensions/extension_helper.h"
13 #include "chrome/renderer/extensions/user_script_slave.h" 13 #include "chrome/renderer/extensions/user_script_slave.h"
14 #include "content/renderer/render_view.h" 14 #include "content/renderer/render_view.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
19 19
20 namespace { 20 namespace {
21 // The length of time to wait after the DOM is complete to try and run user 21 // The length of time to wait after the DOM is complete to try and run user
22 // scripts. 22 // scripts.
23 const int kUserScriptIdleTimeoutMs = 200; 23 const int kUserScriptIdleTimeoutMs = 200;
24 } 24 }
25 25
26 using WebKit::WebDocument;
26 using WebKit::WebFrame; 27 using WebKit::WebFrame;
27 using WebKit::WebString; 28 using WebKit::WebString;
28 using WebKit::WebView; 29 using WebKit::WebView;
29 30
30 UserScriptIdleScheduler::UserScriptIdleScheduler( 31 UserScriptIdleScheduler::UserScriptIdleScheduler(
31 WebFrame* frame, ExtensionDispatcher* extension_dispatcher) 32 WebFrame* frame, ExtensionDispatcher* extension_dispatcher)
32 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 33 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
33 frame_(frame), 34 frame_(frame),
34 has_run_(false), 35 has_run_(false),
35 extension_dispatcher_(extension_dispatcher) { 36 extension_dispatcher_(extension_dispatcher) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 frame->executeScript(source); 145 frame->executeScript(source);
145 } else { 146 } else {
146 std::vector<WebScriptSource> sources; 147 std::vector<WebScriptSource> sources;
147 sources.push_back(source); 148 sources.push_back(source);
148 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); 149 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
149 frame->executeScriptInIsolatedWorld( 150 frame->executeScriptInIsolatedWorld(
150 UserScriptSlave::GetIsolatedWorldId(extension, frame), 151 UserScriptSlave::GetIsolatedWorldId(extension, frame),
151 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); 152 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
152 } 153 }
153 } else { 154 } else {
154 frame->document().insertStyleText( 155 frame->document().insertUserStyleSheet(
155 WebString::fromUTF8(params.code), WebString()); 156 WebString::fromUTF8(params.code),
157 // Author level is consistent with WebView::addUserStyleSheet.
158 WebDocument::UserStyleAuthorLevel);
156 } 159 }
157 } 160 }
158 161
159 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished( 162 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished(
160 render_view->routing_id(), params.request_id, true, "")); 163 render_view->routing_id(), params.request_id, true, ""));
161 } 164 }
162 165
163 bool UserScriptIdleScheduler::GetAllChildFrames( 166 bool UserScriptIdleScheduler::GetAllChildFrames(
164 WebFrame* parent_frame, 167 WebFrame* parent_frame,
165 std::vector<WebFrame*>* frames_vector) const { 168 std::vector<WebFrame*>* frames_vector) const {
166 if (!parent_frame) 169 if (!parent_frame)
167 return false; 170 return false;
168 171
169 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; 172 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
170 child_frame = child_frame->nextSibling()) { 173 child_frame = child_frame->nextSibling()) {
171 frames_vector->push_back(child_frame); 174 frames_vector->push_back(child_frame);
172 GetAllChildFrames(child_frame, frames_vector); 175 GetAllChildFrames(child_frame, frames_vector);
173 } 176 }
174 return true; 177 return true;
175 } 178 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.cc ('k') | chrome/test/data/extensions/api_test/executescript/basic/test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698