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

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

Issue 8786008: Silently swallow exceptions in extension bindings callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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/chrome_v8_context.h" 5 #include "chrome/renderer/extensions/chrome_v8_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/extensions/extension_set.h" 10 #include "chrome/common/extensions/extension_set.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 else 76 else
77 return NULL; 77 return NULL;
78 } 78 }
79 79
80 bool ChromeV8Context::CallChromeHiddenMethod( 80 bool ChromeV8Context::CallChromeHiddenMethod(
81 const std::string& function_name, 81 const std::string& function_name,
82 int argc, 82 int argc,
83 v8::Handle<v8::Value>* argv, 83 v8::Handle<v8::Value>* argv,
84 v8::Handle<v8::Value>* result) const { 84 v8::Handle<v8::Value>* result) const {
85 v8::Context::Scope context_scope(v8_context_); 85 v8::Context::Scope context_scope(v8_context_);
86 v8::TryCatch try_catch;
87 86
88 // Look up the function name, which may be a sub-property like 87 // Look up the function name, which may be a sub-property like
89 // "Port.dispatchOnMessage" in the hidden global variable. 88 // "Port.dispatchOnMessage" in the hidden global variable.
90 v8::Local<v8::Value> value = v8::Local<v8::Value>::New(GetChromeHidden()); 89 v8::Local<v8::Value> value = v8::Local<v8::Value>::New(GetChromeHidden());
91 if (value.IsEmpty()) 90 if (value.IsEmpty())
92 return false; 91 return false;
93 92
94 std::vector<std::string> components; 93 std::vector<std::string> components;
95 base::SplitStringDontTrim(function_name, '.', &components); 94 base::SplitStringDontTrim(function_name, '.', &components);
96 for (size_t i = 0; i < components.size(); ++i) { 95 for (size_t i = 0; i < components.size(); ++i) {
97 if (!value.IsEmpty() && value->IsObject()) { 96 if (!value.IsEmpty() && value->IsObject()) {
98 value = v8::Local<v8::Object>::Cast(value)->Get( 97 value = v8::Local<v8::Object>::Cast(value)->Get(
99 v8::String::New(components[i].c_str())); 98 v8::String::New(components[i].c_str()));
100 if (try_catch.HasCaught()) {
101 NOTREACHED() << *v8::String::AsciiValue(try_catch.Exception());
102 return false;
103 }
104 } 99 }
105 } 100 }
106 101
107 if (value.IsEmpty() || !value->IsFunction()) { 102 if (value.IsEmpty() || !value->IsFunction()) {
108 VLOG(1) << "Could not execute chrome hidden method: " << function_name; 103 VLOG(1) << "Could not execute chrome hidden method: " << function_name;
109 return false; 104 return false;
110 } 105 }
111 106
112 v8::Handle<v8::Value> result_temp = 107 v8::Handle<v8::Value> result_temp =
113 v8::Local<v8::Function>::Cast(value)->Call(v8::Object::New(), argc, argv); 108 v8::Local<v8::Function>::Cast(value)->Call(v8::Object::New(), argc, argv);
114 if (try_catch.HasCaught()) {
115 NOTREACHED() << *v8::String::AsciiValue(try_catch.Exception());
116 return false;
117 }
118 if (result) 109 if (result)
119 *result = result_temp; 110 *result = result_temp;
120 return true; 111 return true;
121 } 112 }
122 113
123 void ChromeV8Context::DispatchOnLoadEvent(bool is_extension_process, 114 void ChromeV8Context::DispatchOnLoadEvent(bool is_extension_process,
124 bool is_incognito_process) const { 115 bool is_incognito_process) const {
125 v8::HandleScope handle_scope; 116 v8::HandleScope handle_scope;
126 v8::Handle<v8::Value> argv[3]; 117 v8::Handle<v8::Value> argv[3];
127 argv[0] = v8::String::New(extension_id_.c_str()); 118 argv[0] = v8::String::New(extension_id_.c_str());
128 argv[1] = v8::Boolean::New(is_extension_process); 119 argv[1] = v8::Boolean::New(is_extension_process);
129 argv[2] = v8::Boolean::New(is_incognito_process); 120 argv[2] = v8::Boolean::New(is_incognito_process);
130 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); 121 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL);
131 } 122 }
132 123
133 void ChromeV8Context::DispatchOnUnloadEvent() const { 124 void ChromeV8Context::DispatchOnUnloadEvent() const {
134 v8::HandleScope handle_scope; 125 v8::HandleScope handle_scope;
135 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); 126 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL);
136 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698