| Index: chrome/test/chromedriver/chrome/chrome_impl.cc | 
| diff --git a/chrome/test/chromedriver/chrome/chrome_impl.cc b/chrome/test/chromedriver/chrome/chrome_impl.cc | 
| index 5665d49a90239f343e75dc58026b096066df1827..a6f75ab94d3a3b67dcd124d279d9a433e04e50e5 100644 | 
| --- a/chrome/test/chromedriver/chrome/chrome_impl.cc | 
| +++ b/chrome/test/chromedriver/chrome/chrome_impl.cc | 
| @@ -213,39 +213,71 @@ std::string ChromeImpl::GetVersion() { | 
| return version_; | 
| } | 
|  | 
| -Status ChromeImpl::GetWebViews(std::list<WebView*>* web_views) { | 
| +Status ChromeImpl::GetWebViewIds(std::list<std::string>* web_view_ids) { | 
| WebViewInfoList info_list; | 
| Status status = FetchWebViewsInfo( | 
| context_getter_, port_, &info_list); | 
| if (status.IsError()) | 
| return status; | 
|  | 
| -  std::list<WebView*> internal_web_views; | 
| +  // Check if some web views are closed. | 
| +  std::list<std::string>::iterator it = web_view_ids_.begin(); | 
| +  while (it != web_view_ids_.end()) { | 
| +    if (!GetWebViewFromList(*it, info_list)) { | 
| +      web_view_map_.erase(*it); | 
| +      it = web_view_ids_.erase(it); | 
| +    } else { | 
| +      ++it; | 
| +    } | 
| +  } | 
| + | 
| +  // Check for newly-opened web views. | 
| for (WebViewInfoList::const_iterator it = info_list.begin(); | 
| it != info_list.end(); ++it) { | 
| -    WebViewMap::const_iterator found = web_view_map_.find(it->id); | 
| -    if (found != web_view_map_.end()) { | 
| -      internal_web_views.push_back(found->second.get()); | 
| +    if (it->type != internal::WebViewInfo::kPage) | 
| continue; | 
| -    } | 
|  | 
| -    std::string ws_url = base::StringPrintf( | 
| -        "ws://127.0.0.1:%d/devtools/page/%s", port_, it->id.c_str()); | 
| -    DevToolsClientImpl::FrontendCloserFunc frontend_closer_func = base::Bind( | 
| -        &CloseDevToolsFrontend, this, socket_factory_, | 
| -        context_getter_, port_, it->id); | 
| -    web_view_map_[it->id] = make_linked_ptr(new WebViewImpl( | 
| -        it->id, | 
| -        new DevToolsClientImpl(socket_factory_, ws_url, frontend_closer_func), | 
| -        this, | 
| -        base::Bind(&CloseWebView, context_getter_, port_, it->id))); | 
| -    internal_web_views.push_back(web_view_map_[it->id].get()); | 
| +    if (std::find(web_view_ids_.begin(), web_view_ids_.end(), it->id) == | 
| +        web_view_ids_.end()) { | 
| +      web_view_ids_.push_back(it->id); | 
| +    } | 
| } | 
|  | 
| -  web_views->swap(internal_web_views); | 
| +  *web_view_ids = web_view_ids_; | 
| return Status(kOk); | 
| } | 
|  | 
| +Status ChromeImpl::GetWebViewById(const std::string& id, WebView** web_view) { | 
| +  WebViewMap::const_iterator found = web_view_map_.find(id); | 
| +  if (found != web_view_map_.end()) { | 
| +    *web_view = found->second.get(); | 
| +    return Status(kOk); | 
| +  } | 
| + | 
| +  WebViewInfoList info_list; | 
| +  Status status = FetchWebViewsInfo(context_getter_, port_, &info_list); | 
| +  if (status.IsError()) | 
| +    return status; | 
| +  for (WebViewInfoList::const_iterator it = info_list.begin(); | 
| +       it != info_list.end(); ++it) { | 
| +    if (it->id == id && it->type == internal::WebViewInfo::kPage) { | 
| +      std::string ws_url = base::StringPrintf( | 
| +          "ws://127.0.0.1:%d/devtools/page/%s", port_, it->id.c_str()); | 
| +      DevToolsClientImpl::FrontendCloserFunc frontend_closer_func = base::Bind( | 
| +          &CloseDevToolsFrontend, this, socket_factory_, | 
| +          context_getter_, port_, it->id); | 
| +      web_view_map_[it->id] = make_linked_ptr(new WebViewImpl( | 
| +          it->id, | 
| +          new DevToolsClientImpl(socket_factory_, ws_url, frontend_closer_func), | 
| +          this, | 
| +          base::Bind(&CloseWebView, context_getter_, port_, it->id))); | 
| +      *web_view = web_view_map_[it->id].get(); | 
| +      return Status(kOk); | 
| +    } | 
| +  } | 
| +  return Status(kUnknownError, "web view not found"); | 
| +} | 
| + | 
| Status ChromeImpl::IsJavaScriptDialogOpen(bool* is_open) { | 
| JavaScriptDialogManager* manager; | 
| Status status = GetDialogManagerForOpenDialog(&manager); | 
| @@ -279,6 +311,7 @@ Status ChromeImpl::HandleJavaScriptDialog(bool accept, | 
| } | 
|  | 
| void ChromeImpl::OnWebViewClose(WebView* web_view) { | 
| +  web_view_ids_.remove(web_view->GetId()); | 
| web_view_map_.erase(web_view->GetId()); | 
| } | 
|  | 
| @@ -317,15 +350,19 @@ int ChromeImpl::GetPort() const { | 
|  | 
| Status ChromeImpl::GetDialogManagerForOpenDialog( | 
| JavaScriptDialogManager** manager) { | 
| -  std::list<WebView*> web_views; | 
| -  Status status = GetWebViews(&web_views); | 
| +  std::list<std::string> web_view_ids; | 
| +  Status status = GetWebViewIds(&web_view_ids); | 
| if (status.IsError()) | 
| return status; | 
|  | 
| -  for (std::list<WebView*>::const_iterator it = web_views.begin(); | 
| -       it != web_views.end(); ++it) { | 
| -    if ((*it)->GetJavaScriptDialogManager()->IsDialogOpen()) { | 
| -      *manager = (*it)->GetJavaScriptDialogManager(); | 
| +  for (std::list<std::string>::const_iterator it = web_view_ids.begin(); | 
| +       it != web_view_ids.end(); ++it) { | 
| +    WebView* web_view; | 
| +    status = GetWebViewById(*it, &web_view); | 
| +    if (status.IsError()) | 
| +      return status; | 
| +    if (web_view->GetJavaScriptDialogManager()->IsDialogOpen()) { | 
| +      *manager = web_view->GetJavaScriptDialogManager(); | 
| return Status(kOk); | 
| } | 
| } | 
|  |