Commit 640e303c authored by mgiuca@chromium.org's avatar mgiuca@chromium.org

app.window: Replace linear view search with direct lookup.

Added method RenderView::FromRoutingID to expose internal lookup function.

BUG=155398


Review URL: https://chromiumcodereview.appspot.com/11316160

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171117 0039d316-1c4b-4281-b951-d872f2087c98
parent d72f9100
...@@ -60,27 +60,6 @@ AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher) ...@@ -60,27 +60,6 @@ AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher)
} }
namespace { namespace {
class FindViewByID : public content::RenderViewVisitor {
public:
explicit FindViewByID(int route_id) : route_id_(route_id), view_(NULL) {
}
content::RenderView* view() { return view_; }
// Returns false to terminate the iteration.
virtual bool Visit(content::RenderView* render_view) {
if (render_view->GetRoutingID() == route_id_) {
view_ = render_view;
return false;
}
return true;
}
private:
int route_id_;
content::RenderView* view_;
};
class LoadWatcher : public content::RenderViewObserver { class LoadWatcher : public content::RenderViewObserver {
public: public:
LoadWatcher( LoadWatcher(
...@@ -134,9 +113,7 @@ v8::Handle<v8::Value> AppWindowCustomBindings::OnContextReady( ...@@ -134,9 +113,7 @@ v8::Handle<v8::Value> AppWindowCustomBindings::OnContextReady(
int view_id = args[0]->Int32Value(); int view_id = args[0]->Int32Value();
FindViewByID view_finder(view_id); content::RenderView* view = content::RenderView::FromRoutingID(view_id);
content::RenderView::ForEach(&view_finder);
content::RenderView* view = view_finder.view();
if (!view) if (!view)
return v8::Undefined(); return v8::Undefined();
...@@ -166,14 +143,7 @@ v8::Handle<v8::Value> AppWindowCustomBindings::GetView( ...@@ -166,14 +143,7 @@ v8::Handle<v8::Value> AppWindowCustomBindings::GetView(
if (view_id == MSG_ROUTING_NONE) if (view_id == MSG_ROUTING_NONE)
return v8::Undefined(); return v8::Undefined();
// TODO(jeremya): there exists a direct map of routing_id -> RenderView as content::RenderView* view = content::RenderView::FromRoutingID(view_id);
// ChildThread::current()->ResolveRoute(), but ResolveRoute returns an
// IPC::Listener*, which RenderView doesn't inherit from (RenderViewImpl
// does, indirectly, via RenderWidget, but the link isn't exposed outside of
// content/.)
FindViewByID view_finder(view_id);
content::RenderView::ForEach(&view_finder);
content::RenderView* view = view_finder.view();
if (!view) if (!view)
return v8::Undefined(); return v8::Undefined();
......
...@@ -47,6 +47,9 @@ class CONTENT_EXPORT RenderView : public IPC::Sender { ...@@ -47,6 +47,9 @@ class CONTENT_EXPORT RenderView : public IPC::Sender {
// Returns the RenderView containing the given WebView. // Returns the RenderView containing the given WebView.
static RenderView* FromWebView(WebKit::WebView* webview); static RenderView* FromWebView(WebKit::WebView* webview);
// Returns the RenderView for the given routing ID.
static RenderView* FromRoutingID(int routing_id);
// Visit all RenderViews with a live WebView (i.e., RenderViews that have // Visit all RenderViews with a live WebView (i.e., RenderViews that have
// been closed but not yet destroyed are excluded). // been closed but not yet destroyed are excluded).
static void ForEach(RenderViewVisitor* visitor); static void ForEach(RenderViewVisitor* visitor);
......
...@@ -371,12 +371,6 @@ static const size_t kContentIntentDelayMilliseconds = 700; ...@@ -371,12 +371,6 @@ static const size_t kContentIntentDelayMilliseconds = 700;
static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
NULL; NULL;
static RenderViewImpl* FromRoutingID(int32 routing_id) {
RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
RoutingIDViewMap::iterator it = views->find(routing_id);
return it == views->end() ? NULL : it->second;
}
static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) {
for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) {
if (frame->identifier() == frame_id) if (frame->identifier() == frame_id)
...@@ -784,6 +778,18 @@ RenderView* RenderView::FromWebView(WebKit::WebView* webview) { ...@@ -784,6 +778,18 @@ RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
return RenderViewImpl::FromWebView(webview); return RenderViewImpl::FromWebView(webview);
} }
/*static*/
RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
RoutingIDViewMap::iterator it = views->find(routing_id);
return it == views->end() ? NULL : it->second;
}
/*static*/
RenderView* RenderView::FromRoutingID(int routing_id) {
return RenderViewImpl::FromRoutingID(routing_id);
}
/*static*/ /*static*/
void RenderView::ForEach(RenderViewVisitor* visitor) { void RenderView::ForEach(RenderViewVisitor* visitor) {
ViewMap* views = g_view_map.Pointer(); ViewMap* views = g_view_map.Pointer();
......
...@@ -225,6 +225,9 @@ class CONTENT_EXPORT RenderViewImpl ...@@ -225,6 +225,9 @@ class CONTENT_EXPORT RenderViewImpl
// Returns the RenderViewImpl containing the given WebView. // Returns the RenderViewImpl containing the given WebView.
static RenderViewImpl* FromWebView(WebKit::WebView* webview); static RenderViewImpl* FromWebView(WebKit::WebView* webview);
// Returns the RenderViewImpl for the given routing ID.
static RenderViewImpl* FromRoutingID(int routing_id);
// May return NULL when the view is closing. // May return NULL when the view is closing.
WebKit::WebView* webview() const; WebKit::WebView* webview() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment