Index: chrome/renderer/extensions/app_window_custom_bindings.cc |
diff --git a/chrome/renderer/extensions/app_window_custom_bindings.cc b/chrome/renderer/extensions/app_window_custom_bindings.cc |
index 5337e8dfb5190656ba9c9047ec52dd063c9b6ea0..396e80f36c7d24561c7b9ba72455b81e3f881851 100644 |
--- a/chrome/renderer/extensions/app_window_custom_bindings.cc |
+++ b/chrome/renderer/extensions/app_window_custom_bindings.cc |
@@ -10,16 +10,17 @@ |
#include "chrome/common/extensions/extension_action.h" |
#include "chrome/common/extensions/extension_messages.h" |
#include "chrome/common/url_constants.h" |
+#include "chrome/renderer/extensions/chrome_v8_context.h" |
#include "chrome/renderer/extensions/dispatcher.h" |
#include "chrome/renderer/extensions/extension_helper.h" |
#include "content/public/renderer/render_thread.h" |
#include "content/public/renderer/render_view.h" |
#include "grit/renderer_resources.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" |
#include "v8/include/v8.h" |
#include "webkit/glue/webkit_glue.h" |
@@ -28,9 +29,54 @@ |
namespace extensions { |
+class DidCreateDocumentElementObserver : public content::RenderViewObserver { |
+ public: |
+ DidCreateDocumentElementObserver( |
+ content::RenderView* view, Dispatcher* dispatcher, bool inject_titlebar) |
+ : content::RenderViewObserver(view), dispatcher_(dispatcher), |
+ inject_titlebar_(inject_titlebar) { |
+ } |
+ virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) { |
Mihai Parparita -not on Chrome
2012/08/30 01:13:47
Nit: OVERRIDE
jeremya
2012/08/30 02:21:02
Done.
|
+ v8::HandleScope handle_scope; |
+ DCHECK(frame); |
+ DCHECK(dispatcher_); |
+ ChromeV8Context* v8_context = |
+ dispatcher_->v8_context_set().GetByV8Context( |
+ frame->mainWorldScriptContext()); |
+ |
+ if (!v8_context) |
+ return; |
+ v8::Context::Scope context_scope(v8_context->v8_context()); |
+ |
+ v8::Local<v8::Value> inject_app_titlebar = |
+ v8::Local<v8::Value>::New( |
+ v8_context->module_system()->RequireForJsInner( |
+ v8::String::New("injectAppTitlebar"))); |
+ if (inject_app_titlebar.IsEmpty()) |
+ return; |
+ v8::Local<v8::Value> value = |
+ v8::Local<v8::Object>::Cast(inject_app_titlebar)->Get( |
abarth-chromium
2012/08/29 23:51:20
How do you know this case is legit? We should pro
jeremya
2012/08/30 02:21:02
Done.
|
+ v8::String::New("didCreateDocumentElement")); |
+ DCHECK(!value.IsEmpty() && value->IsFunction()); |
abarth-chromium
2012/08/29 23:51:20
How do you know these conditions are met? These a
jeremya
2012/08/30 02:21:02
I believe the v8 extensions system is sufficient t
|
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
+ v8::Handle<v8::Value> argv[1]; |
+ argv[0] = v8::Boolean::New(inject_titlebar_); |
+ frame->callFunctionEvenIfScriptDisabled(function, |
+ v8::Object::New(), |
+ arraysize(argv), |
+ argv); |
+ } |
+ |
+ private: |
+ Dispatcher* dispatcher_; |
+ bool inject_titlebar_; |
+}; |
+ |
AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher) |
: ChromeV8Extension(dispatcher) { |
- RouteStaticFunction("GetView", &GetView); |
+ RouteFunction("GetView", |
+ base::Bind(&AppWindowCustomBindings::GetView, |
+ base::Unretained(this))); |
} |
namespace { |
@@ -60,14 +106,19 @@ v8::Handle<v8::Value> AppWindowCustomBindings::GetView( |
const v8::Arguments& args) { |
// TODO(jeremya): convert this to IDL nocompile to get validation, and turn |
// these argument checks into CHECK(). |
- if (args.Length() != 1) |
+ if (args.Length() != 2) |
return v8::Undefined(); |
if (!args[0]->IsInt32()) |
return v8::Undefined(); |
+ if (!args[1]->IsBoolean()) |
+ return v8::Undefined(); |
+ |
int view_id = args[0]->Int32Value(); |
+ bool inject_titlebar = args[1]->BooleanValue(); |
+ |
if (view_id == MSG_ROUTING_NONE) |
return v8::Undefined(); |
@@ -82,6 +133,8 @@ v8::Handle<v8::Value> AppWindowCustomBindings::GetView( |
if (!view) |
return v8::Undefined(); |
+ new DidCreateDocumentElementObserver(view, dispatcher(), inject_titlebar); |
abarth-chromium
2012/08/29 23:51:20
I assume someone else manages the lifetime of this
jeremya
2012/08/30 02:21:02
See content/public/renderer/render_view_observer.h
|
+ |
// TODO(jeremya): it doesn't really make sense to set the opener here, but we |
// need to make sure the security origin is set up before returning the DOM |
// reference. A better way to do this would be to have the browser pass the |