| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/debugger/browser_list_tabcontents_provider.h" | |
| 6 | |
| 7 #include "base/path_service.h" | |
| 8 #include "chrome/browser/history/top_sites.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/profiles/profile_manager.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_commands.h" | |
| 13 #include "chrome/browser/ui/browser_list.h" | |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 15 #include "chrome/common/chrome_paths.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "content/public/common/url_constants.h" | |
| 19 #include "grit/devtools_discovery_page_resources.h" | |
| 20 #include "net/url_request/url_request_context_getter.h" | |
| 21 #include "ui/base/resource/resource_bundle.h" | |
| 22 | |
| 23 using content::DevToolsHttpHandlerDelegate; | |
| 24 using content::RenderViewHost; | |
| 25 | |
| 26 BrowserListTabContentsProvider::BrowserListTabContentsProvider( | |
| 27 Profile* profile) | |
| 28 : profile_(profile) { | |
| 29 } | |
| 30 | |
| 31 BrowserListTabContentsProvider::~BrowserListTabContentsProvider() { | |
| 32 } | |
| 33 | |
| 34 std::string BrowserListTabContentsProvider::GetDiscoveryPageHTML() { | |
| 35 std::set<Profile*> profiles; | |
| 36 for (BrowserList::const_iterator it = BrowserList::begin(), | |
| 37 end = BrowserList::end(); it != end; ++it) { | |
| 38 profiles.insert((*it)->profile()); | |
| 39 } | |
| 40 for (std::set<Profile*>::iterator it = profiles.begin(); | |
| 41 it != profiles.end(); ++it) { | |
| 42 history::TopSites* ts = (*it)->GetTopSites(); | |
| 43 if (ts) { | |
| 44 // TopSites updates itself after a delay. Ask TopSites to update itself | |
| 45 // when we're about to show the remote debugging landing page. | |
| 46 ts->SyncWithHistory(); | |
| 47 } | |
| 48 } | |
| 49 return ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 50 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | |
| 51 } | |
| 52 | |
| 53 bool BrowserListTabContentsProvider::BundlesFrontendResources() { | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() { | |
| 58 #if defined(DEBUG_DEVTOOLS) | |
| 59 FilePath inspector_dir; | |
| 60 PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir); | |
| 61 return inspector_dir; | |
| 62 #else | |
| 63 return FilePath(); | |
| 64 #endif | |
| 65 } | |
| 66 | |
| 67 std::string BrowserListTabContentsProvider::GetPageThumbnailData( | |
| 68 const GURL& url) { | |
| 69 for (BrowserList::const_iterator it = BrowserList::begin(), | |
| 70 end = BrowserList::end(); it != end; ++it) { | |
| 71 Profile* profile = (*it)->profile(); | |
| 72 history::TopSites* top_sites = profile->GetTopSites(); | |
| 73 if (!top_sites) | |
| 74 continue; | |
| 75 scoped_refptr<base::RefCountedMemory> data; | |
| 76 if (top_sites->GetPageThumbnail(url, &data)) | |
| 77 return std::string( | |
| 78 reinterpret_cast<const char*>(data->front()), data->size()); | |
| 79 } | |
| 80 | |
| 81 return std::string(); | |
| 82 } | |
| 83 | |
| 84 RenderViewHost* BrowserListTabContentsProvider::CreateNewTarget() { | |
| 85 if (BrowserList::empty()) | |
| 86 chrome::NewEmptyWindow(profile_); | |
| 87 | |
| 88 if (BrowserList::empty()) | |
| 89 return NULL; | |
| 90 | |
| 91 content::WebContents* web_contents = chrome::AddSelectedTabWithURL( | |
| 92 *BrowserList::begin(), | |
| 93 GURL(chrome::kAboutBlankURL), | |
| 94 content::PAGE_TRANSITION_LINK); | |
| 95 return web_contents->GetRenderViewHost(); | |
| 96 } | |
| OLD | NEW |