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

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

Issue 10896032: HTML titlebars for v2 apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kludge test fix for mac Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
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/extensions/app_window_custom_bindings.h" 5 #include "chrome/renderer/extensions/app_window_custom_bindings.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_util.h"
10 #include "chrome/common/extensions/extension_action.h"
11 #include "chrome/common/extensions/extension_messages.h" 9 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/url_constants.h" 10 #include "chrome/renderer/extensions/chrome_v8_context.h"
13 #include "chrome/renderer/extensions/dispatcher.h" 11 #include "chrome/renderer/extensions/dispatcher.h"
14 #include "chrome/renderer/extensions/extension_helper.h"
15 #include "content/public/renderer/render_thread.h" 12 #include "content/public/renderer/render_thread.h"
16 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
17 #include "grit/renderer_resources.h" 14 #include "content/public/renderer/render_view_observer.h"
15 #include "content/public/renderer/render_view_visitor.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h "
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
23 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
24 #include "webkit/glue/webkit_glue.h"
25
26 #include "content/public/renderer/render_view.h"
27 #include "content/public/renderer/render_view_visitor.h"
28 19
29 namespace extensions { 20 namespace extensions {
30 21
22 class DidCreateDocumentElementObserver : public content::RenderViewObserver {
23 public:
24 DidCreateDocumentElementObserver(
25 content::RenderView* view, Dispatcher* dispatcher)
26 : content::RenderViewObserver(view), dispatcher_(dispatcher) {
27 }
28
29 virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE {
30 v8::HandleScope handle_scope;
31 DCHECK(frame);
32 DCHECK(dispatcher_);
33 ChromeV8Context* v8_context =
34 dispatcher_->v8_context_set().GetByV8Context(
35 frame->mainWorldScriptContext());
36
37 if (!v8_context)
38 return;
39 v8::Context::Scope context_scope(v8_context->v8_context());
40 v8_context->module_system()->CallModuleMethod(
41 "injectAppTitlebar", "didCreateDocumentElement");
42 }
43
44 private:
45 Dispatcher* dispatcher_;
46 };
47
31 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher) 48 AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher)
32 : ChromeV8Extension(dispatcher) { 49 : ChromeV8Extension(dispatcher) {
33 RouteStaticFunction("GetView", &GetView); 50 RouteFunction("GetView",
51 base::Bind(&AppWindowCustomBindings::GetView,
52 base::Unretained(this)));
34 } 53 }
35 54
36 namespace { 55 namespace {
37 class FindViewByID : public content::RenderViewVisitor { 56 class FindViewByID : public content::RenderViewVisitor {
38 public: 57 public:
39 explicit FindViewByID(int route_id) : route_id_(route_id), view_(NULL) { 58 explicit FindViewByID(int route_id) : route_id_(route_id), view_(NULL) {
40 } 59 }
41 60
42 content::RenderView* view() { return view_; } 61 content::RenderView* view() { return view_; }
43 62
44 // Returns false to terminate the iteration. 63 // Returns false to terminate the iteration.
45 virtual bool Visit(content::RenderView* render_view) { 64 virtual bool Visit(content::RenderView* render_view) {
46 if (render_view->GetRoutingID() == route_id_) { 65 if (render_view->GetRoutingID() == route_id_) {
47 view_ = render_view; 66 view_ = render_view;
48 return false; 67 return false;
49 } 68 }
50 return true; 69 return true;
51 } 70 }
52 71
53 private: 72 private:
54 int route_id_; 73 int route_id_;
55 content::RenderView* view_; 74 content::RenderView* view_;
56 }; 75 };
57 } // namespace 76 } // namespace
58 77
59 v8::Handle<v8::Value> AppWindowCustomBindings::GetView( 78 v8::Handle<v8::Value> AppWindowCustomBindings::GetView(
60 const v8::Arguments& args) { 79 const v8::Arguments& args) {
61 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn 80 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn
62 // these argument checks into CHECK(). 81 // these argument checks into CHECK().
63 if (args.Length() != 1) 82 if (args.Length() != 2)
64 return v8::Undefined(); 83 return v8::Undefined();
65 84
66 if (!args[0]->IsInt32()) 85 if (!args[0]->IsInt32())
67 return v8::Undefined(); 86 return v8::Undefined();
68 87
88 if (!args[1]->IsBoolean())
89 return v8::Undefined();
90
69 int view_id = args[0]->Int32Value(); 91 int view_id = args[0]->Int32Value();
70 92
93 bool inject_titlebar = args[1]->BooleanValue();
94
71 if (view_id == MSG_ROUTING_NONE) 95 if (view_id == MSG_ROUTING_NONE)
72 return v8::Undefined(); 96 return v8::Undefined();
73 97
74 // TODO(jeremya): there exists a direct map of routing_id -> RenderView as 98 // TODO(jeremya): there exists a direct map of routing_id -> RenderView as
75 // ChildThread::current()->ResolveRoute(), but ResolveRoute returns an 99 // ChildThread::current()->ResolveRoute(), but ResolveRoute returns an
76 // IPC::Listener*, which RenderView doesn't inherit from (RenderViewImpl 100 // IPC::Listener*, which RenderView doesn't inherit from (RenderViewImpl
77 // does, indirectly, via RenderWidget, but the link isn't exposed outside of 101 // does, indirectly, via RenderWidget, but the link isn't exposed outside of
78 // content/.) 102 // content/.)
79 FindViewByID view_finder(view_id); 103 FindViewByID view_finder(view_id);
80 content::RenderView::ForEach(&view_finder); 104 content::RenderView::ForEach(&view_finder);
81 content::RenderView* view = view_finder.view(); 105 content::RenderView* view = view_finder.view();
82 if (!view) 106 if (!view)
83 return v8::Undefined(); 107 return v8::Undefined();
84 108
109 if (inject_titlebar)
110 new DidCreateDocumentElementObserver(view, dispatcher());
111
85 // TODO(jeremya): it doesn't really make sense to set the opener here, but we 112 // TODO(jeremya): it doesn't really make sense to set the opener here, but we
86 // need to make sure the security origin is set up before returning the DOM 113 // need to make sure the security origin is set up before returning the DOM
87 // reference. A better way to do this would be to have the browser pass the 114 // reference. A better way to do this would be to have the browser pass the
88 // opener through so opener_id is set in RenderViewImpl's constructor. 115 // opener through so opener_id is set in RenderViewImpl's constructor.
89 content::RenderView* render_view = GetCurrentRenderView(); 116 content::RenderView* render_view = GetCurrentRenderView();
90 if (!render_view) 117 if (!render_view)
91 return v8::Undefined(); 118 return v8::Undefined();
92 WebKit::WebFrame* opener = render_view->GetWebView()->mainFrame(); 119 WebKit::WebFrame* opener = render_view->GetWebView()->mainFrame();
93 WebKit::WebFrame* frame = view->GetWebView()->mainFrame(); 120 WebKit::WebFrame* frame = view->GetWebView()->mainFrame();
94 frame->setOpener(opener); 121 frame->setOpener(opener);
95 content::RenderThread::Get()->Send( 122 content::RenderThread::Get()->Send(
96 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); 123 new ExtensionHostMsg_ResumeRequests(view->GetRoutingID()));
97 124
98 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); 125 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global();
99 return window; 126 return window;
100 } 127 }
101 128
102 } // namespace extensions 129 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/app_window_custom_bindings.h ('k') | chrome/renderer/extensions/chrome_v8_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698