OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/principals_extension_bindings.h" | 5 #include "chrome/renderer/principals_extension_bindings.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "content/public/renderer/render_view.h" | 8 #include "content/public/renderer/render_view.h" |
9 #include "third_party/WebKit/public/web/WebDocument.h" | 9 #include "third_party/WebKit/public/web/WebDocument.h" |
10 #include "third_party/WebKit/public/web/WebFrame.h" | 10 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
11 #include "third_party/WebKit/public/web/WebView.h" | 11 #include "third_party/WebKit/public/web/WebView.h" |
12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
13 | 13 |
14 using blink::WebFrame; | 14 using blink::WebLocalFrame; |
15 using blink::WebView; | 15 using blink::WebView; |
16 using content::RenderView; | 16 using content::RenderView; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class PrincipalsExtensionWrapper : public v8::Extension { | 20 class PrincipalsExtensionWrapper : public v8::Extension { |
21 public: | 21 public: |
22 PrincipalsExtensionWrapper(); | 22 PrincipalsExtensionWrapper(); |
23 | 23 |
24 private: | 24 private: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 void PrincipalsExtensionWrapper::GetManagedAccounts( | 72 void PrincipalsExtensionWrapper::GetManagedAccounts( |
73 const v8::FunctionCallbackInfo<v8::Value>& args) { | 73 const v8::FunctionCallbackInfo<v8::Value>& args) { |
74 RenderView* render_view = GetRenderView(); | 74 RenderView* render_view = GetRenderView(); |
75 if (!render_view) { | 75 if (!render_view) { |
76 args.GetReturnValue().SetNull(); | 76 args.GetReturnValue().SetNull(); |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 std::vector<std::string> accounts; | 80 std::vector<std::string> accounts; |
81 render_view->Send(new ChromeViewHostMsg_GetManagedAccounts( | 81 render_view->Send(new ChromeViewHostMsg_GetManagedAccounts( |
82 WebFrame::frameForCurrentContext()->document().url(), | 82 WebLocalFrame::frameForCurrentContext()->document().url(), |
83 &accounts)); | 83 &accounts)); |
84 | 84 |
85 v8::Isolate* isolate = args.GetIsolate(); | 85 v8::Isolate* isolate = args.GetIsolate(); |
86 v8::Local<v8::Array> v8_result = v8::Array::New(isolate); | 86 v8::Local<v8::Array> v8_result = v8::Array::New(isolate); |
87 int v8_index = 0; | 87 int v8_index = 0; |
88 for (std::vector<std::string>::const_iterator it = accounts.begin(); | 88 for (std::vector<std::string>::const_iterator it = accounts.begin(); |
89 it != accounts.end(); ++it) { | 89 it != accounts.end(); ++it) { |
90 v8_result->Set(v8::Integer::New(isolate, v8_index++), | 90 v8_result->Set(v8::Integer::New(isolate, v8_index++), |
91 v8::String::NewFromUtf8(isolate, it->c_str(), | 91 v8::String::NewFromUtf8(isolate, it->c_str(), |
92 v8::String::kNormalString, it->length())); | 92 v8::String::kNormalString, it->length())); |
93 } | 93 } |
94 args.GetReturnValue().Set(v8_result); | 94 args.GetReturnValue().Set(v8_result); |
95 } | 95 } |
96 | 96 |
97 void PrincipalsExtensionWrapper::ShowBrowserAccountManagementUI( | 97 void PrincipalsExtensionWrapper::ShowBrowserAccountManagementUI( |
98 const v8::FunctionCallbackInfo<v8::Value>& args) { | 98 const v8::FunctionCallbackInfo<v8::Value>& args) { |
99 // TODO(guohui): need to figure out how to prevent abuse. | 99 // TODO(guohui): need to figure out how to prevent abuse. |
100 RenderView* render_view = GetRenderView(); | 100 RenderView* render_view = GetRenderView(); |
101 if (!render_view) return; | 101 if (!render_view) return; |
102 | 102 |
103 render_view->Send(new ChromeViewHostMsg_ShowBrowserAccountManagementUI()); | 103 render_view->Send(new ChromeViewHostMsg_ShowBrowserAccountManagementUI()); |
104 } | 104 } |
105 | 105 |
106 RenderView* PrincipalsExtensionWrapper::GetRenderView() { | 106 RenderView* PrincipalsExtensionWrapper::GetRenderView() { |
107 WebFrame* webframe = WebFrame::frameForCurrentContext(); | 107 WebLocalFrame* webframe = WebLocalFrame::frameForCurrentContext(); |
108 DCHECK(webframe) << "There should be an active frame since we just got " | 108 DCHECK(webframe) << "There should be an active frame since we just got " |
109 "a native function called."; | 109 "a native function called."; |
110 if (!webframe) | 110 if (!webframe) |
111 return NULL; | 111 return NULL; |
112 | 112 |
113 WebView* webview = webframe->view(); | 113 WebView* webview = webframe->view(); |
114 if (!webview) // can happen during closing | 114 if (!webview) // can happen during closing |
115 return NULL; | 115 return NULL; |
116 | 116 |
117 return RenderView::FromWebView(webview); | 117 return RenderView::FromWebView(webview); |
118 } | 118 } |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 | 121 |
122 namespace extensions_v8 { | 122 namespace extensions_v8 { |
123 | 123 |
124 v8::Extension* PrincipalsExtension::Get() { | 124 v8::Extension* PrincipalsExtension::Get() { |
125 return new PrincipalsExtensionWrapper(); | 125 return new PrincipalsExtensionWrapper(); |
126 } | 126 } |
127 | 127 |
128 } // namespace extensions_v8 | 128 } // namespace extensions_v8 |
OLD | NEW |