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

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

Issue 10443105: Take 2 at implementing activeTab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: empty -> is_empty Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_scheduler.h" 5 #include "chrome/renderer/extensions/user_script_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/common/extensions/extension_error_utils.h" 9 #include "chrome/common/extensions/extension_error_utils.h"
10 #include "chrome/common/extensions/extension_manifest_constants.h" 10 #include "chrome/common/extensions/extension_manifest_constants.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 void UserScriptScheduler::ExecuteCodeImpl( 130 void UserScriptScheduler::ExecuteCodeImpl(
131 const ExtensionMsg_ExecuteCode_Params& params) { 131 const ExtensionMsg_ExecuteCode_Params& params) {
132 const Extension* extension = extension_dispatcher_->extensions()->GetByID( 132 const Extension* extension = extension_dispatcher_->extensions()->GetByID(
133 params.extension_id); 133 params.extension_id);
134 content::RenderView* render_view = 134 content::RenderView* render_view =
135 content::RenderView::FromWebView(frame_->view()); 135 content::RenderView::FromWebView(frame_->view());
136 ExtensionHelper* extension_helper = ExtensionHelper::Get(render_view);
136 137
137 // Since extension info is sent separately from user script info, they can 138 // Since extension info is sent separately from user script info, they can
138 // be out of sync. We just ignore this situation. 139 // be out of sync. We just ignore this situation.
139 if (!extension) { 140 if (!extension) {
140 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished( 141 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished(
141 render_view->GetRoutingID(), params.request_id, true, -1, "")); 142 render_view->GetRoutingID(), params.request_id, true, -1, ""));
142 return; 143 return;
143 } 144 }
144 145
145 std::vector<WebFrame*> frame_vector; 146 std::vector<WebFrame*> frame_vector;
146 frame_vector.push_back(frame_); 147 frame_vector.push_back(frame_);
147 if (params.all_frames) 148 if (params.all_frames)
148 GetAllChildFrames(frame_, &frame_vector); 149 GetAllChildFrames(frame_, &frame_vector);
149 150
150 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); 151 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
151 frame_it != frame_vector.end(); ++frame_it) { 152 frame_it != frame_vector.end(); ++frame_it) {
152 WebFrame* frame = *frame_it; 153 WebFrame* frame = *frame_it;
153 if (params.is_javascript) { 154 if (params.is_javascript) {
154 // We recheck access here in the renderer for extra safety against races 155 // We recheck access here in the renderer for extra safety against races
155 // with navigation. 156 // with navigation.
156 // 157 //
157 // But different frames can have different URLs, and the extension might 158 // But different frames can have different URLs, and the extension might
158 // only have access to a subset of them. For the top frame, we can 159 // only have access to a subset of them. For the top frame, we can
159 // immediately send an error and stop because the browser process 160 // immediately send an error and stop because the browser process
160 // considers that an error too. 161 // considers that an error too.
161 // 162 //
162 // For child frames, we just skip ones the extension doesn't have access 163 // For child frames, we just skip ones the extension doesn't have access
163 // to and carry on. 164 // to and carry on.
164 if (!extension->CanExecuteScriptOnPage(frame->document().url(), 165 if (!extension->CanExecuteScriptOnPage(frame->document().url(),
165 NULL, NULL)) { 166 extension_helper->tab_id(),
167 NULL,
168 NULL)) {
166 if (frame->parent()) { 169 if (frame->parent()) {
167 continue; 170 continue;
168 } else { 171 } else {
169 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished( 172 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished(
170 render_view->GetRoutingID(), 173 render_view->GetRoutingID(),
171 params.request_id, 174 params.request_id,
172 false, 175 false,
173 -1, 176 -1,
174 ExtensionErrorUtils::FormatErrorMessage( 177 ExtensionErrorUtils::FormatErrorMessage(
175 extension_manifest_errors::kCannotAccessPage, 178 extension_manifest_errors::kCannotAccessPage,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (!parent_frame) 214 if (!parent_frame)
212 return false; 215 return false;
213 216
214 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; 217 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
215 child_frame = child_frame->nextSibling()) { 218 child_frame = child_frame->nextSibling()) {
216 frames_vector->push_back(child_frame); 219 frames_vector->push_back(child_frame);
217 GetAllChildFrames(child_frame, frames_vector); 220 GetAllChildFrames(child_frame, frames_vector);
218 } 221 }
219 return true; 222 return true;
220 } 223 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/tab_finder.cc ('k') | chrome/renderer/extensions/user_script_slave.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698