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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const char kExternalExtensionName[] = "v8/External"; | 36 const char kExternalExtensionName[] = "v8/External"; |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 class ExternalExtensionWrapper : public v8::Extension { | 40 class ExternalExtensionWrapper : public v8::Extension { |
41 public: | 41 public: |
42 ExternalExtensionWrapper(); | 42 ExternalExtensionWrapper(); |
43 | 43 |
44 // Allows v8's javascript code to call the native functions defined | 44 // Allows v8's javascript code to call the native functions defined |
45 // in this class for window.external. | 45 // in this class for window.external. |
46 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 46 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
47 v8::Isolate* isolate, | 47 v8::Isolate* isolate, |
48 v8::Handle<v8::String> name) override; | 48 v8::Local<v8::String> name) override; |
49 | 49 |
50 // Helper function to find the RenderView. May return NULL. | 50 // Helper function to find the RenderView. May return NULL. |
51 static RenderView* GetRenderView(); | 51 static RenderView* GetRenderView(); |
52 | 52 |
53 // Implementation of window.external.AddSearchProvider. | 53 // Implementation of window.external.AddSearchProvider. |
54 static void AddSearchProvider( | 54 static void AddSearchProvider( |
55 const v8::FunctionCallbackInfo<v8::Value>& args); | 55 const v8::FunctionCallbackInfo<v8::Value>& args); |
56 | 56 |
57 // Implementation of window.external.IsSearchProviderInstalled. | 57 // Implementation of window.external.IsSearchProviderInstalled. |
58 static void IsSearchProviderInstalled( | 58 static void IsSearchProviderInstalled( |
59 const v8::FunctionCallbackInfo<v8::Value>& args); | 59 const v8::FunctionCallbackInfo<v8::Value>& args); |
60 | 60 |
61 private: | 61 private: |
62 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionWrapper); | 62 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionWrapper); |
63 }; | 63 }; |
64 | 64 |
65 ExternalExtensionWrapper::ExternalExtensionWrapper() | 65 ExternalExtensionWrapper::ExternalExtensionWrapper() |
66 : v8::Extension(kExternalExtensionName, kSearchProviderApi) { | 66 : v8::Extension(kExternalExtensionName, kSearchProviderApi) { |
67 } | 67 } |
68 | 68 |
69 v8::Handle<v8::FunctionTemplate> | 69 v8::Local<v8::FunctionTemplate> |
70 ExternalExtensionWrapper::GetNativeFunctionTemplate( | 70 ExternalExtensionWrapper::GetNativeFunctionTemplate( |
71 v8::Isolate* isolate, | 71 v8::Isolate* isolate, |
72 v8::Handle<v8::String> name) { | 72 v8::Local<v8::String> name) { |
73 if (name->Equals(v8::String::NewFromUtf8(isolate, "NativeAddSearchProvider"))) | 73 if (name->Equals(v8::String::NewFromUtf8(isolate, "NativeAddSearchProvider"))) |
74 return v8::FunctionTemplate::New(isolate, AddSearchProvider); | 74 return v8::FunctionTemplate::New(isolate, AddSearchProvider); |
75 | 75 |
76 if (name->Equals(v8::String::NewFromUtf8( | 76 if (name->Equals(v8::String::NewFromUtf8( |
77 isolate, "NativeIsSearchProviderInstalled"))) { | 77 isolate, "NativeIsSearchProviderInstalled"))) { |
78 return v8::FunctionTemplate::New(isolate, IsSearchProviderInstalled); | 78 return v8::FunctionTemplate::New(isolate, IsSearchProviderInstalled); |
79 } | 79 } |
80 | 80 |
81 return v8::Handle<v8::FunctionTemplate>(); | 81 return v8::Local<v8::FunctionTemplate>(); |
82 } | 82 } |
83 | 83 |
84 // static | 84 // static |
85 RenderView* ExternalExtensionWrapper::GetRenderView() { | 85 RenderView* ExternalExtensionWrapper::GetRenderView() { |
86 WebLocalFrame* webframe = WebLocalFrame::frameForCurrentContext(); | 86 WebLocalFrame* webframe = WebLocalFrame::frameForCurrentContext(); |
87 DCHECK(webframe) << "There should be an active frame since we just got " | 87 DCHECK(webframe) << "There should be an active frame since we just got " |
88 "a native function called."; | 88 "a native function called."; |
89 if (!webframe) | 89 if (!webframe) |
90 return NULL; | 90 return NULL; |
91 | 91 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return; | 158 return; |
159 } | 159 } |
160 args.GetReturnValue().Set(static_cast<int32_t>(install)); | 160 args.GetReturnValue().Set(static_cast<int32_t>(install)); |
161 } | 161 } |
162 | 162 |
163 v8::Extension* ExternalExtension::Get() { | 163 v8::Extension* ExternalExtension::Get() { |
164 return new ExternalExtensionWrapper(); | 164 return new ExternalExtensionWrapper(); |
165 } | 165 } |
166 | 166 |
167 } // namespace extensions_v8 | 167 } // namespace extensions_v8 |
OLD | NEW |