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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/extension_process_bindings.cc
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index e3cfe0a764baf3aa2ddfe01a1e3234e2036c8d43..58c301db98237e73a0a5d126f9443df208a3fd08 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -204,11 +204,14 @@ class ExtensionImpl : public ExtensionBase {
// be an extension URL.
static std::string ExtensionIdForCurrentContext() {
RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
- DCHECK(renderview);
+ if (!renderview)
+ return std::string(); // this can happen as a tab is closing.
+
GURL url = renderview->webview()->mainFrame()->url();
- if (url.SchemeIs(chrome::kExtensionScheme))
- return url.host();
- return std::string();
+ if (!url.SchemeIs(chrome::kExtensionScheme))
+ return std::string();
+
+ return url.host();
}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
@@ -272,7 +275,11 @@ class ExtensionImpl : public ExtensionBase {
}
int browser_window_id = render_view->browser_window_id();
- ExtensionViewAccumulator popup_matcher(ExtensionIdForCurrentContext(),
+ std::string extension_id = ExtensionIdForCurrentContext();
+ if (extension_id.empty())
+ return v8::Undefined();
+
+ ExtensionViewAccumulator popup_matcher(extension_id,
browser_window_id,
viewtype_to_find);
RenderView::ForEach(&popup_matcher);
@@ -321,8 +328,12 @@ class ExtensionImpl : public ExtensionBase {
return v8::Undefined();
}
- ExtensionViewAccumulator accumulator(
- ExtensionIdForCurrentContext(), browser_window_id, view_type);
+ std::string extension_id = ExtensionIdForCurrentContext();
+ if (extension_id.empty())
+ return v8::Undefined();
+
+ ExtensionViewAccumulator accumulator(extension_id, browser_window_id,
+ view_type);
RenderView::ForEach(&accumulator);
return accumulator.views();
}
@@ -383,8 +394,11 @@ class ExtensionImpl : public ExtensionBase {
return v8::Undefined();
}
- L10nMessagesMap* l10n_messages =
- GetL10nMessagesMap(ExtensionIdForCurrentContext());
+ std::string extension_id = ExtensionIdForCurrentContext();
+ if (extension_id.empty())
+ return v8::Undefined();
+
+ L10nMessagesMap* l10n_messages = GetL10nMessagesMap(extension_id);
if (!l10n_messages)
return v8::Undefined();
@@ -641,6 +655,9 @@ static std::string GetPermissionName(const std::string& function_name) {
bool ExtensionProcessBindings::CurrentContextHasPermission(
const std::string& function_name) {
std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext();
+ if (extension_id.empty())
+ return false;
+
PermissionsMap& permissions_map = *GetPermissionsMap(extension_id);
std::string permission_name = GetPermissionName(function_name);
PermissionsMap::iterator it = permissions_map.find(permission_name);
« 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