OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/renderer/external_extension.h" | 5 #include "chrome/renderer/external_extension.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/common/search_provider.h" | 8 #include "chrome/common/search_provider.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
10 #include "third_party/WebKit/public/web/WebDocument.h" | 10 #include "third_party/WebKit/public/web/WebDocument.h" |
11 #include "third_party/WebKit/public/web/WebFrame.h" | 11 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
12 #include "third_party/WebKit/public/web/WebView.h" | 12 #include "third_party/WebKit/public/web/WebView.h" |
13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
14 | 14 |
15 using blink::WebFrame; | 15 using blink::WebLocalFrame; |
16 using blink::WebView; | 16 using blink::WebView; |
17 using content::RenderView; | 17 using content::RenderView; |
18 | 18 |
19 namespace extensions_v8 { | 19 namespace extensions_v8 { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char* const kSearchProviderApi = | 23 const char* const kSearchProviderApi = |
24 "var external;" | 24 "var external;" |
25 "if (!external)" | 25 "if (!external)" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 if (name->Equals( | 76 if (name->Equals( |
77 v8::String::NewFromUtf8(isolate, "NativeIsSearchProviderInstalled"))) | 77 v8::String::NewFromUtf8(isolate, "NativeIsSearchProviderInstalled"))) |
78 return v8::FunctionTemplate::New(isolate, IsSearchProviderInstalled); | 78 return v8::FunctionTemplate::New(isolate, IsSearchProviderInstalled); |
79 | 79 |
80 return v8::Handle<v8::FunctionTemplate>(); | 80 return v8::Handle<v8::FunctionTemplate>(); |
81 } | 81 } |
82 | 82 |
83 // static | 83 // static |
84 RenderView* ExternalExtensionWrapper::GetRenderView() { | 84 RenderView* ExternalExtensionWrapper::GetRenderView() { |
85 WebFrame* webframe = WebFrame::frameForCurrentContext(); | 85 WebLocalFrame* webframe = WebLocalFrame::frameForCurrentContext(); |
86 DCHECK(webframe) << "There should be an active frame since we just got " | 86 DCHECK(webframe) << "There should be an active frame since we just got " |
87 "a native function called."; | 87 "a native function called."; |
88 if (!webframe) return NULL; | 88 if (!webframe) return NULL; |
89 | 89 |
90 WebView* webview = webframe->view(); | 90 WebView* webview = webframe->view(); |
91 if (!webview) return NULL; // can happen during closing | 91 if (!webview) return NULL; // can happen during closing |
92 | 92 |
93 return RenderView::FromWebView(webview); | 93 return RenderView::FromWebView(webview); |
94 } | 94 } |
95 | 95 |
(...skipping 20 matching lines...) Expand all Loading... |
116 void ExternalExtensionWrapper::IsSearchProviderInstalled( | 116 void ExternalExtensionWrapper::IsSearchProviderInstalled( |
117 const v8::FunctionCallbackInfo<v8::Value>& args) { | 117 const v8::FunctionCallbackInfo<v8::Value>& args) { |
118 if (!args.Length() || !args[0]->IsString()) return; | 118 if (!args.Length() || !args[0]->IsString()) return; |
119 v8::String::Utf8Value utf8name(args[0]); | 119 v8::String::Utf8Value utf8name(args[0]); |
120 if (!utf8name.length()) return; | 120 if (!utf8name.length()) return; |
121 | 121 |
122 std::string name(*utf8name); | 122 std::string name(*utf8name); |
123 RenderView* render_view = GetRenderView(); | 123 RenderView* render_view = GetRenderView(); |
124 if (!render_view) return; | 124 if (!render_view) return; |
125 | 125 |
126 WebFrame* webframe = WebFrame::frameForCurrentContext(); | 126 WebLocalFrame* webframe = WebLocalFrame::frameForCurrentContext(); |
127 if (!webframe) return; | 127 if (!webframe) return; |
128 | 128 |
129 search_provider::InstallState install = search_provider::DENIED; | 129 search_provider::InstallState install = search_provider::DENIED; |
130 GURL inquiry_url = GURL(name); | 130 GURL inquiry_url = GURL(name); |
131 if (!inquiry_url.is_empty()) { | 131 if (!inquiry_url.is_empty()) { |
132 render_view->Send(new ChromeViewHostMsg_GetSearchProviderInstallState( | 132 render_view->Send(new ChromeViewHostMsg_GetSearchProviderInstallState( |
133 render_view->GetRoutingID(), | 133 render_view->GetRoutingID(), |
134 webframe->document().url(), | 134 webframe->document().url(), |
135 inquiry_url, | 135 inquiry_url, |
136 &install)); | 136 &install)); |
137 } | 137 } |
138 | 138 |
139 if (install == search_provider::DENIED) { | 139 if (install == search_provider::DENIED) { |
140 // FIXME: throw access denied exception. | 140 // FIXME: throw access denied exception. |
141 v8::Isolate* isolate = args.GetIsolate(); | 141 v8::Isolate* isolate = args.GetIsolate(); |
142 isolate->ThrowException(v8::Exception::Error(v8::String::Empty(isolate))); | 142 isolate->ThrowException(v8::Exception::Error(v8::String::Empty(isolate))); |
143 return; | 143 return; |
144 } | 144 } |
145 args.GetReturnValue().Set(static_cast<int32_t>(install)); | 145 args.GetReturnValue().Set(static_cast<int32_t>(install)); |
146 } | 146 } |
147 | 147 |
148 v8::Extension* ExternalExtension::Get() { | 148 v8::Extension* ExternalExtension::Get() { |
149 return new ExternalExtensionWrapper(); | 149 return new ExternalExtensionWrapper(); |
150 } | 150 } |
151 | 151 |
152 } // namespace extensions_v8 | 152 } // namespace extensions_v8 |
OLD | NEW |