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

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

Issue 441005: Stab-in-the-dark at fixing a top crasher. GetCurrentRenderView() can (Closed)
Patch Set: Created 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_process_bindings.h" 5 #include "chrome/renderer/extensions/extension_process_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 for (size_t i = 0; i < names.size(); ++i) { 197 for (size_t i = 0; i < names.size(); ++i) {
198 name_set->insert(names[i]); 198 name_set->insert(names[i]);
199 } 199 }
200 } 200 }
201 201
202 // Note: do not call this function before or during the chromeHidden.onLoad 202 // Note: do not call this function before or during the chromeHidden.onLoad
203 // event dispatch. The URL might not have been committed yet and might not 203 // event dispatch. The URL might not have been committed yet and might not
204 // be an extension URL. 204 // be an extension URL.
205 static std::string ExtensionIdForCurrentContext() { 205 static std::string ExtensionIdForCurrentContext() {
206 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); 206 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
207 DCHECK(renderview); 207 if (!renderview)
208 return std::string(); // this can happen as a tab is closing.
209
208 GURL url = renderview->webview()->mainFrame()->url(); 210 GURL url = renderview->webview()->mainFrame()->url();
209 if (url.SchemeIs(chrome::kExtensionScheme)) 211 if (!url.SchemeIs(chrome::kExtensionScheme))
210 return url.host(); 212 return std::string();
211 return std::string(); 213
214 return url.host();
212 } 215 }
213 216
214 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 217 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
215 v8::Handle<v8::String> name) { 218 v8::Handle<v8::String> name) {
216 if (name->Equals(v8::String::New("GetExtensionAPIDefinition"))) { 219 if (name->Equals(v8::String::New("GetExtensionAPIDefinition"))) {
217 return v8::FunctionTemplate::New(GetExtensionAPIDefinition); 220 return v8::FunctionTemplate::New(GetExtensionAPIDefinition);
218 } else if (name->Equals(v8::String::New("GetExtensionViews"))) { 221 } else if (name->Equals(v8::String::New("GetExtensionViews"))) {
219 return v8::FunctionTemplate::New(GetExtensionViews); 222 return v8::FunctionTemplate::New(GetExtensionViews);
220 } else if (name->Equals(v8::String::New("GetNextRequestId"))) { 223 } else if (name->Equals(v8::String::New("GetNextRequestId"))) {
221 return v8::FunctionTemplate::New(GetNextRequestId); 224 return v8::FunctionTemplate::New(GetNextRequestId);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 268
266 // Disallow searching for a host view if we are a popup view, and likewise 269 // Disallow searching for a host view if we are a popup view, and likewise
267 // if we are a toolstrip view. 270 // if we are a toolstrip view.
268 RenderView* render_view = bindings_utils::GetRenderViewForCurrentContext(); 271 RenderView* render_view = bindings_utils::GetRenderViewForCurrentContext();
269 if (!render_view || 272 if (!render_view ||
270 render_view->view_type() == viewtype_to_find) { 273 render_view->view_type() == viewtype_to_find) {
271 return v8::Undefined(); 274 return v8::Undefined();
272 } 275 }
273 276
274 int browser_window_id = render_view->browser_window_id(); 277 int browser_window_id = render_view->browser_window_id();
275 ExtensionViewAccumulator popup_matcher(ExtensionIdForCurrentContext(), 278 std::string extension_id = ExtensionIdForCurrentContext();
279 if (extension_id.empty())
280 return v8::Undefined();
281
282 ExtensionViewAccumulator popup_matcher(extension_id,
276 browser_window_id, 283 browser_window_id,
277 viewtype_to_find); 284 viewtype_to_find);
278 RenderView::ForEach(&popup_matcher); 285 RenderView::ForEach(&popup_matcher);
279 286
280 if (0 == popup_matcher.views()->Length()) 287 if (0 == popup_matcher.views()->Length())
281 return v8::Undefined(); 288 return v8::Undefined();
282 DCHECK(popup_matcher.views()->Has(0)); 289 DCHECK(popup_matcher.views()->Has(0));
283 290
284 // Return the first view found. 291 // Return the first view found.
285 return popup_matcher.views()->Get(v8::Integer::New(0)); 292 return popup_matcher.views()->Get(v8::Integer::New(0));
(...skipping 28 matching lines...) Expand all
314 } else if (view_type_string == ViewType::kBackgroundPage) { 321 } else if (view_type_string == ViewType::kBackgroundPage) {
315 view_type = ViewType::EXTENSION_BACKGROUND_PAGE; 322 view_type = ViewType::EXTENSION_BACKGROUND_PAGE;
316 } else if (view_type_string == ViewType::kTabContents) { 323 } else if (view_type_string == ViewType::kTabContents) {
317 view_type = ViewType::TAB_CONTENTS; 324 view_type = ViewType::TAB_CONTENTS;
318 } else if (view_type_string == ViewType::kPopup) { 325 } else if (view_type_string == ViewType::kPopup) {
319 view_type = ViewType::EXTENSION_POPUP; 326 view_type = ViewType::EXTENSION_POPUP;
320 } else if (view_type_string != ViewType::kAll) { 327 } else if (view_type_string != ViewType::kAll) {
321 return v8::Undefined(); 328 return v8::Undefined();
322 } 329 }
323 330
324 ExtensionViewAccumulator accumulator( 331 std::string extension_id = ExtensionIdForCurrentContext();
325 ExtensionIdForCurrentContext(), browser_window_id, view_type); 332 if (extension_id.empty())
333 return v8::Undefined();
334
335 ExtensionViewAccumulator accumulator(extension_id, browser_window_id,
336 view_type);
326 RenderView::ForEach(&accumulator); 337 RenderView::ForEach(&accumulator);
327 return accumulator.views(); 338 return accumulator.views();
328 } 339 }
329 340
330 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { 341 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) {
331 static int next_request_id = 0; 342 static int next_request_id = 0;
332 return v8::Integer::New(next_request_id++); 343 return v8::Integer::New(next_request_id++);
333 } 344 }
334 345
335 // Creates a new messaging channel to the tab with the given ID. 346 // Creates a new messaging channel to the tab with the given ID.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 387
377 return page_action_vector; 388 return page_action_vector;
378 } 389 }
379 390
380 static v8::Handle<v8::Value> GetL10nMessage(const v8::Arguments& args) { 391 static v8::Handle<v8::Value> GetL10nMessage(const v8::Arguments& args) {
381 if (args.Length() != 2 || !args[0]->IsString()) { 392 if (args.Length() != 2 || !args[0]->IsString()) {
382 NOTREACHED() << "Bad arguments"; 393 NOTREACHED() << "Bad arguments";
383 return v8::Undefined(); 394 return v8::Undefined();
384 } 395 }
385 396
386 L10nMessagesMap* l10n_messages = 397 std::string extension_id = ExtensionIdForCurrentContext();
387 GetL10nMessagesMap(ExtensionIdForCurrentContext()); 398 if (extension_id.empty())
399 return v8::Undefined();
400
401 L10nMessagesMap* l10n_messages = GetL10nMessagesMap(extension_id);
388 if (!l10n_messages) 402 if (!l10n_messages)
389 return v8::Undefined(); 403 return v8::Undefined();
390 404
391 std::string message_name = *v8::String::AsciiValue(args[0]); 405 std::string message_name = *v8::String::AsciiValue(args[0]);
392 std::string message = 406 std::string message =
393 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages); 407 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages);
394 408
395 std::vector<std::string> substitutions; 409 std::vector<std::string> substitutions;
396 if (args[1]->IsNull() || args[1]->IsUndefined()) { 410 if (args[1]->IsNull() || args[1]->IsUndefined()) {
397 // chrome.i18n.getMessage("message_name"); 411 // chrome.i18n.getMessage("message_name");
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 std::string permission_name = function_name.substr(0, first_dot); 648 std::string permission_name = function_name.substr(0, first_dot);
635 if (permission_name == "windows") 649 if (permission_name == "windows")
636 return "tabs"; // windows and tabs are the same permission. 650 return "tabs"; // windows and tabs are the same permission.
637 return permission_name; 651 return permission_name;
638 } 652 }
639 653
640 // static 654 // static
641 bool ExtensionProcessBindings::CurrentContextHasPermission( 655 bool ExtensionProcessBindings::CurrentContextHasPermission(
642 const std::string& function_name) { 656 const std::string& function_name) {
643 std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext(); 657 std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext();
658 if (extension_id.empty())
659 return false;
660
644 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id); 661 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id);
645 std::string permission_name = GetPermissionName(function_name); 662 std::string permission_name = GetPermissionName(function_name);
646 PermissionsMap::iterator it = permissions_map.find(permission_name); 663 PermissionsMap::iterator it = permissions_map.find(permission_name);
647 664
648 // We explicitly check if the permission entry is present and false, because 665 // We explicitly check if the permission entry is present and false, because
649 // some APIs do not have a required permission entry (ie, "chrome.extension"). 666 // some APIs do not have a required permission entry (ie, "chrome.extension").
650 return (it == permissions_map.end() || it->second); 667 return (it == permissions_map.end() || it->second);
651 } 668 }
652 669
653 // static 670 // static
(...skipping 24 matching lines...) Expand all
678 return; 695 return;
679 696
680 v8::HandleScope handle_scope; 697 v8::HandleScope handle_scope;
681 WebFrame* frame = view->mainFrame(); 698 WebFrame* frame = view->mainFrame();
682 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 699 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
683 v8::Handle<v8::Value> argv[1]; 700 v8::Handle<v8::Value> argv[1];
684 argv[0] = v8::String::New(type_str); 701 argv[0] = v8::String::New(type_str);
685 bindings_utils::CallFunctionInContext(context, "setViewType", 702 bindings_utils::CallFunctionInContext(context, "setViewType",
686 arraysize(argv), argv); 703 arraysize(argv), argv);
687 } 704 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698