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

Side by Side Diff: content/renderer/web_ui_extension.cc

Issue 611483002: Fix for crash when attaching a frame in WebUI renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: As suggested, factored out the solution and used in other extensions. Created 6 years, 2 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
« no previous file with comments | « content/renderer/skia_benchmarking_extension.cc ('k') | 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "content/renderer/web_ui_extension.h" 5 #include "content/renderer/web_ui_extension.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "content/common/view_messages.h" 9 #include "content/common/view_messages.h"
10 #include "content/public/common/bindings_policy.h" 10 #include "content/public/common/bindings_policy.h"
11 #include "content/public/common/url_constants.h" 11 #include "content/public/common/url_constants.h"
12 #include "content/public/renderer/render_thread.h" 12 #include "content/public/renderer/render_thread.h"
13 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
14 #include "content/public/renderer/v8_value_converter.h" 14 #include "content/public/renderer/v8_value_converter.h"
15 #include "content/renderer/chrome_object_extensions_utils.h"
15 #include "content/renderer/web_ui_extension_data.h" 16 #include "content/renderer/web_ui_extension_data.h"
16 #include "gin/arguments.h" 17 #include "gin/arguments.h"
17 #include "gin/function_template.h" 18 #include "gin/function_template.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebKit.h" 20 #include "third_party/WebKit/public/web/WebKit.h"
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" 21 #include "third_party/WebKit/public/web/WebLocalFrame.h"
21 #include "third_party/WebKit/public/web/WebView.h" 22 #include "third_party/WebKit/public/web/WebView.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 #include "v8/include/v8.h" 24 #include "v8/include/v8.h"
24 25
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // a value was set by the browser. Else will return an empty string. 63 // a value was set by the browser. Else will return an empty string.
63 void WebUIExtension::Install(blink::WebFrame* frame) { 64 void WebUIExtension::Install(blink::WebFrame* frame) {
64 v8::Isolate* isolate = blink::mainThreadIsolate(); 65 v8::Isolate* isolate = blink::mainThreadIsolate();
65 v8::HandleScope handle_scope(isolate); 66 v8::HandleScope handle_scope(isolate);
66 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 67 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
67 if (context.IsEmpty()) 68 if (context.IsEmpty())
68 return; 69 return;
69 70
70 v8::Context::Scope context_scope(context); 71 v8::Context::Scope context_scope(context);
71 72
72 v8::Handle<v8::Object> global = context->Global(); 73 v8::Handle<v8::Object> chrome = GetOrCreateChromeObject(isolate,
73 v8::Handle<v8::Object> chrome = 74 context->Global());
74 global->Get(gin::StringToV8(isolate, "chrome"))->ToObject();
75 if (chrome.IsEmpty()) {
76 chrome = v8::Object::New(isolate);
77 global->Set(gin::StringToSymbol(isolate, "chrome"), chrome);
78 }
79 chrome->Set(gin::StringToSymbol(isolate, "send"), 75 chrome->Set(gin::StringToSymbol(isolate, "send"),
80 gin::CreateFunctionTemplate( 76 gin::CreateFunctionTemplate(
81 isolate, base::Bind(&WebUIExtension::Send))->GetFunction()); 77 isolate, base::Bind(&WebUIExtension::Send))->GetFunction());
82 chrome->Set(gin::StringToSymbol(isolate, "getVariableValue"), 78 chrome->Set(gin::StringToSymbol(isolate, "getVariableValue"),
83 gin::CreateFunctionTemplate( 79 gin::CreateFunctionTemplate(
84 isolate, base::Bind(&WebUIExtension::GetVariableValue)) 80 isolate, base::Bind(&WebUIExtension::GetVariableValue))
85 ->GetFunction()); 81 ->GetFunction());
86 } 82 }
87 83
88 // static 84 // static
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 std::string WebUIExtension::GetVariableValue(const std::string& name) { 127 std::string WebUIExtension::GetVariableValue(const std::string& name) {
132 blink::WebFrame* frame; 128 blink::WebFrame* frame;
133 RenderView* render_view; 129 RenderView* render_view;
134 if (!ShouldRespondToRequest(&frame, &render_view)) 130 if (!ShouldRespondToRequest(&frame, &render_view))
135 return std::string(); 131 return std::string();
136 132
137 return WebUIExtensionData::Get(render_view)->GetValue(name); 133 return WebUIExtensionData::Get(render_view)->GetValue(name);
138 } 134 }
139 135
140 } // namespace content 136 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/skia_benchmarking_extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698