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

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

Issue 8759018: Be more careful when calling methods on chromeHidden (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar 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
« 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) 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 26 matching lines...) Expand all
37 else 37 else
38 return NULL; 38 return NULL;
39 } 39 }
40 40
41 bool ChromeV8Context::CallChromeHiddenMethod( 41 bool ChromeV8Context::CallChromeHiddenMethod(
42 const std::string& function_name, 42 const std::string& function_name,
43 int argc, 43 int argc,
44 v8::Handle<v8::Value>* argv, 44 v8::Handle<v8::Value>* argv,
45 v8::Handle<v8::Value>* result) const { 45 v8::Handle<v8::Value>* result) const {
46 v8::Context::Scope context_scope(v8_context_); 46 v8::Context::Scope context_scope(v8_context_);
47 v8::TryCatch try_catch;
Matt Perry 2011/12/01 18:57:29 Meh, this seems like overkill given that: - we now
47 48
48 // Look up the function name, which may be a sub-property like 49 // Look up the function name, which may be a sub-property like
49 // "Port.dispatchOnMessage" in the hidden global variable. 50 // "Port.dispatchOnMessage" in the hidden global variable.
50 v8::Local<v8::Value> value = v8::Local<v8::Value>::New( 51 v8::Local<v8::Value> value = v8::Local<v8::Value>::New(
51 ChromeV8Extension::GetChromeHidden(v8_context_)); 52 ChromeV8Extension::GetChromeHidden(v8_context_));
52 std::vector<std::string> components; 53 std::vector<std::string> components;
53 base::SplitStringDontTrim(function_name, '.', &components); 54 base::SplitStringDontTrim(function_name, '.', &components);
54 for (size_t i = 0; i < components.size(); ++i) { 55 for (size_t i = 0; i < components.size(); ++i) {
55 if (!value.IsEmpty()) { 56 if (!value.IsEmpty() && value->IsObject()) {
Aaron Boodman 2011/12/01 05:58:32 FYI: This is the part that actually fixes the bug,
56 value = v8::Local<v8::Object>::Cast(value)->Get( 57 value = v8::Local<v8::Object>::Cast(value)->Get(
57 v8::String::New(components[i].c_str())); 58 v8::String::New(components[i].c_str()));
59 if (try_catch.HasCaught()) {
60 NOTREACHED() << *v8::String::AsciiValue(try_catch.Exception());
61 return false;
62 }
58 } 63 }
59 } 64 }
60 65
61 // TODO(aa): CHECK that this succeeds. Can't do this now because not all
62 // callers know if the method they are calling exists. Should be able to fix
63 // this when all the bindings are converted to the new framework.
64 if (value.IsEmpty() || !value->IsFunction()) { 66 if (value.IsEmpty() || !value->IsFunction()) {
65 VLOG(1) << "Could not execute chrome hidden method: " << function_name; 67 VLOG(1) << "Could not execute chrome hidden method: " << function_name;
66 return false; 68 return false;
67 } 69 }
68 70
69 v8::Handle<v8::Value> result_temp = 71 v8::Handle<v8::Value> result_temp =
70 v8::Local<v8::Function>::Cast(value)->Call(v8::Object::New(), argc, argv); 72 v8::Local<v8::Function>::Cast(value)->Call(v8::Object::New(), argc, argv);
73 if (try_catch.HasCaught()) {
74 NOTREACHED() << *v8::String::AsciiValue(try_catch.Exception());
75 return false;
76 }
71 if (result) 77 if (result)
72 *result = result_temp; 78 *result = result_temp;
73 return true; 79 return true;
74 } 80 }
75 81
76 void ChromeV8Context::DispatchOnLoadEvent(bool is_extension_process, 82 void ChromeV8Context::DispatchOnLoadEvent(bool is_extension_process,
77 bool is_incognito_process) const { 83 bool is_incognito_process) const {
78 v8::HandleScope handle_scope; 84 v8::HandleScope handle_scope;
79 v8::Handle<v8::Value> argv[3]; 85 v8::Handle<v8::Value> argv[3];
80 argv[0] = v8::String::New(extension_id_.c_str()); 86 argv[0] = v8::String::New(extension_id_.c_str());
81 argv[1] = v8::Boolean::New(is_extension_process); 87 argv[1] = v8::Boolean::New(is_extension_process);
82 argv[2] = v8::Boolean::New(is_incognito_process); 88 argv[2] = v8::Boolean::New(is_incognito_process);
83 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); 89 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL);
84 } 90 }
85 91
86 void ChromeV8Context::DispatchOnUnloadEvent() const { 92 void ChromeV8Context::DispatchOnUnloadEvent() const {
87 v8::HandleScope handle_scope; 93 v8::HandleScope handle_scope;
88 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); 94 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL);
89 } 95 }
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