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

Side by Side Diff: content/renderer/web_ui_mojo.cc

Issue 222973003: Conversion of content_shell target to use WebLocalFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove some TODOs Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/web_ui_mojo.h" 5 #include "content/renderer/web_ui_mojo.h"
6 6
7 #include "content/common/view_messages.h" 7 #include "content/common/view_messages.h"
8 #include "content/public/renderer/render_frame.h" 8 #include "content/public/renderer/render_frame.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "content/renderer/web_ui_mojo_context_state.h" 10 #include "content/renderer/web_ui_mojo_context_state.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SetHandleOnContextState(handle.Pass()); 58 SetHandleOnContextState(handle.Pass());
59 else 59 else
60 pending_handle_ = handle.Pass(); 60 pending_handle_ = handle.Pass();
61 } 61 }
62 62
63 WebUIMojo::~WebUIMojo() { 63 WebUIMojo::~WebUIMojo() {
64 } 64 }
65 65
66 void WebUIMojo::CreateContextState() { 66 void WebUIMojo::CreateContextState() {
67 v8::HandleScope handle_scope(blink::mainThreadIsolate()); 67 v8::HandleScope handle_scope(blink::mainThreadIsolate());
68 blink::WebFrame* frame = render_view()->GetWebView()->mainFrame(); 68 blink::WebFrame* frame =
69 render_view()->GetWebView()->mainFrame()->toWebLocalFrame();
69 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 70 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
70 gin::PerContextData* context_data = gin::PerContextData::From(context); 71 gin::PerContextData* context_data = gin::PerContextData::From(context);
71 WebUIMojoContextStateData* data = new WebUIMojoContextStateData; 72 WebUIMojoContextStateData* data = new WebUIMojoContextStateData;
72 data->state.reset(new WebUIMojoContextState( 73 data->state.reset(new WebUIMojoContextState(
73 render_view()->GetWebView()->mainFrame(), context)); 74 render_view()->GetWebView()->mainFrame(), context));
74 context_data->SetUserData(kWebUIMojoContextStateKey, data); 75 context_data->SetUserData(kWebUIMojoContextStateKey, data);
75 } 76 }
76 77
77 void WebUIMojo::DestroyContextState(v8::Handle<v8::Context> context) { 78 void WebUIMojo::DestroyContextState(v8::Handle<v8::Context> context) {
78 gin::PerContextData* context_data = gin::PerContextData::From(context); 79 gin::PerContextData* context_data = gin::PerContextData::From(context);
(...skipping 10 matching lines...) Expand all
89 90
90 void WebUIMojo::SetHandleOnContextState(mojo::ScopedMessagePipeHandle handle) { 91 void WebUIMojo::SetHandleOnContextState(mojo::ScopedMessagePipeHandle handle) {
91 DCHECK(did_finish_document_load_); 92 DCHECK(did_finish_document_load_);
92 v8::HandleScope handle_scope(blink::mainThreadIsolate()); 93 v8::HandleScope handle_scope(blink::mainThreadIsolate());
93 WebUIMojoContextState* state = GetContextState(); 94 WebUIMojoContextState* state = GetContextState();
94 if (state) 95 if (state)
95 state->SetHandle(handle.Pass()); 96 state->SetHandle(handle.Pass());
96 } 97 }
97 98
98 WebUIMojoContextState* WebUIMojo::GetContextState() { 99 WebUIMojoContextState* WebUIMojo::GetContextState() {
99 blink::WebFrame* frame = render_view()->GetWebView()->mainFrame(); 100 blink::WebLocalFrame* frame =
101 render_view()->GetWebView()->mainFrame()->toWebLocalFrame();
100 v8::HandleScope handle_scope(blink::mainThreadIsolate()); 102 v8::HandleScope handle_scope(blink::mainThreadIsolate());
101 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 103 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
102 gin::PerContextData* context_data = gin::PerContextData::From(context); 104 gin::PerContextData* context_data = gin::PerContextData::From(context);
103 if (!context_data) 105 if (!context_data)
104 return NULL; 106 return NULL;
105 WebUIMojoContextStateData* context_state = 107 WebUIMojoContextStateData* context_state =
106 static_cast<WebUIMojoContextStateData*>( 108 static_cast<WebUIMojoContextStateData*>(
107 context_data->GetUserData(kWebUIMojoContextStateKey)); 109 context_data->GetUserData(kWebUIMojoContextStateKey));
108 return context_state ? context_state->state.get() : NULL; 110 return context_state ? context_state->state.get() : NULL;
109 } 111 }
110 112
111 void WebUIMojo::DidClearWindowObject(blink::WebFrame* frame, int world_id) { 113 void WebUIMojo::DidClearWindowObject(blink::WebLocalFrame* frame,
114 int world_id) {
112 if (frame != render_view()->GetWebView()->mainFrame()) 115 if (frame != render_view()->GetWebView()->mainFrame())
113 return; 116 return;
114 117
115 // NOTE: this function may be called early on twice. From the constructor 118 // NOTE: this function may be called early on twice. From the constructor
116 // mainWorldScriptContext() may trigger this to be called. If we are created 119 // mainWorldScriptContext() may trigger this to be called. If we are created
117 // before the page is loaded (which is very likely), then on first load this 120 // before the page is loaded (which is very likely), then on first load this
118 // is called. In the case of the latter we may have already supplied the 121 // is called. In the case of the latter we may have already supplied the
119 // handle to the context state so that if we destroy now the handle is 122 // handle to the context state so that if we destroy now the handle is
120 // lost. If this is the result of the first load then the contextstate should 123 // lost. If this is the result of the first load then the contextstate should
121 // be empty and we don't need to destroy it. 124 // be empty and we don't need to destroy it.
122 WebUIMojoContextState* state = GetContextState(); 125 WebUIMojoContextState* state = GetContextState();
123 if (state && !state->module_added()) 126 if (state && !state->module_added())
124 return; 127 return;
125 128
126 v8::HandleScope handle_scope(blink::mainThreadIsolate()); 129 v8::HandleScope handle_scope(blink::mainThreadIsolate());
127 DestroyContextState(frame->mainWorldScriptContext()); 130 DestroyContextState(frame->mainWorldScriptContext());
128 CreateContextState(); 131 CreateContextState();
129 } 132 }
130 133
131 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698