OLD | NEW |
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 "chrome/browser/android/dev_tools_manager_delegate_android.h" | 5 #include "chrome/browser/android/dev_tools_manager_delegate_android.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 base::TimeTicks GetLastActiveTimeForAgentHost( | 47 base::TimeTicks GetLastActiveTimeForAgentHost( |
48 scoped_refptr<DevToolsAgentHost> agent_host) { | 48 scoped_refptr<DevToolsAgentHost> agent_host) { |
49 if (WebContents* web_contents = agent_host->GetWebContents()) | 49 if (WebContents* web_contents = agent_host->GetWebContents()) |
50 return web_contents->GetLastActiveTime(); | 50 return web_contents->GetLastActiveTime(); |
51 return base::TimeTicks(); | 51 return base::TimeTicks(); |
52 } | 52 } |
53 | 53 |
54 class TargetBase : public content::DevToolsTarget { | 54 class TargetBase : public content::DevToolsTarget { |
55 public: | 55 public: |
56 // content::DevToolsTarget implementation: | 56 // content::DevToolsTarget implementation: |
57 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 57 virtual std::string GetParentId() const override { return std::string(); } |
58 | 58 |
59 virtual std::string GetTitle() const OVERRIDE { return title_; } | 59 virtual std::string GetTitle() const override { return title_; } |
60 | 60 |
61 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 61 virtual std::string GetDescription() const override { return std::string(); } |
62 | 62 |
63 virtual GURL GetURL() const OVERRIDE { return url_; } | 63 virtual GURL GetURL() const override { return url_; } |
64 | 64 |
65 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 65 virtual GURL GetFaviconURL() const override { return favicon_url_; } |
66 | 66 |
67 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 67 virtual base::TimeTicks GetLastActivityTime() const override { |
68 return last_activity_time_; | 68 return last_activity_time_; |
69 } | 69 } |
70 | 70 |
71 protected: | 71 protected: |
72 explicit TargetBase(WebContents* web_contents) | 72 explicit TargetBase(WebContents* web_contents) |
73 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), | 73 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), |
74 url_(web_contents->GetURL()), | 74 url_(web_contents->GetURL()), |
75 favicon_url_(GetFaviconURLForContents(web_contents)), | 75 favicon_url_(GetFaviconURLForContents(web_contents)), |
76 last_activity_time_(web_contents->GetLastActiveTime()) { | 76 last_activity_time_(web_contents->GetLastActiveTime()) { |
77 } | 77 } |
(...skipping 24 matching lines...) Expand all Loading... |
102 return new TabTarget(tab_id, web_contents); | 102 return new TabTarget(tab_id, web_contents); |
103 } | 103 } |
104 | 104 |
105 static TabTarget* CreateForUnloadedTab(int tab_id, | 105 static TabTarget* CreateForUnloadedTab(int tab_id, |
106 const base::string16& title, | 106 const base::string16& title, |
107 const GURL& url) { | 107 const GURL& url) { |
108 return new TabTarget(tab_id, title, url); | 108 return new TabTarget(tab_id, title, url); |
109 } | 109 } |
110 | 110 |
111 // content::DevToolsTarget implementation: | 111 // content::DevToolsTarget implementation: |
112 virtual std::string GetId() const OVERRIDE { | 112 virtual std::string GetId() const override { |
113 return base::IntToString(tab_id_); | 113 return base::IntToString(tab_id_); |
114 } | 114 } |
115 | 115 |
116 virtual std::string GetType() const OVERRIDE { | 116 virtual std::string GetType() const override { |
117 return kTargetTypePage; | 117 return kTargetTypePage; |
118 } | 118 } |
119 | 119 |
120 virtual bool IsAttached() const OVERRIDE { | 120 virtual bool IsAttached() const override { |
121 TabModel* model; | 121 TabModel* model; |
122 int index; | 122 int index; |
123 if (!FindTab(&model, &index)) | 123 if (!FindTab(&model, &index)) |
124 return false; | 124 return false; |
125 WebContents* web_contents = model->GetWebContentsAt(index); | 125 WebContents* web_contents = model->GetWebContentsAt(index); |
126 if (!web_contents) | 126 if (!web_contents) |
127 return false; | 127 return false; |
128 return DevToolsAgentHost::IsDebuggerAttached(web_contents); | 128 return DevToolsAgentHost::IsDebuggerAttached(web_contents); |
129 } | 129 } |
130 | 130 |
131 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 131 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const override { |
132 TabModel* model; | 132 TabModel* model; |
133 int index; | 133 int index; |
134 if (!FindTab(&model, &index)) | 134 if (!FindTab(&model, &index)) |
135 return NULL; | 135 return NULL; |
136 WebContents* web_contents = model->GetWebContentsAt(index); | 136 WebContents* web_contents = model->GetWebContentsAt(index); |
137 if (!web_contents) { | 137 if (!web_contents) { |
138 // The tab has been pushed out of memory, pull it back. | 138 // The tab has been pushed out of memory, pull it back. |
139 TabAndroid* tab = model->GetTabAt(index); | 139 TabAndroid* tab = model->GetTabAt(index); |
140 if (!tab) | 140 if (!tab) |
141 return NULL; | 141 return NULL; |
142 | 142 |
143 if (!tab->LoadIfNeeded()) | 143 if (!tab->LoadIfNeeded()) |
144 return NULL; | 144 return NULL; |
145 | 145 |
146 web_contents = model->GetWebContentsAt(index); | 146 web_contents = model->GetWebContentsAt(index); |
147 if (!web_contents) | 147 if (!web_contents) |
148 return NULL; | 148 return NULL; |
149 } | 149 } |
150 return DevToolsAgentHost::GetOrCreateFor(web_contents); | 150 return DevToolsAgentHost::GetOrCreateFor(web_contents); |
151 } | 151 } |
152 | 152 |
153 virtual bool Activate() const OVERRIDE { | 153 virtual bool Activate() const override { |
154 TabModel* model; | 154 TabModel* model; |
155 int index; | 155 int index; |
156 if (!FindTab(&model, &index)) | 156 if (!FindTab(&model, &index)) |
157 return false; | 157 return false; |
158 model->SetActiveIndex(index); | 158 model->SetActiveIndex(index); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 virtual bool Close() const OVERRIDE { | 162 virtual bool Close() const override { |
163 TabModel* model; | 163 TabModel* model; |
164 int index; | 164 int index; |
165 if (!FindTab(&model, &index)) | 165 if (!FindTab(&model, &index)) |
166 return false; | 166 return false; |
167 model->CloseTabAt(index); | 167 model->CloseTabAt(index); |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 private: | 171 private: |
172 TabTarget(int tab_id, WebContents* web_contents) | 172 TabTarget(int tab_id, WebContents* web_contents) |
(...skipping 26 matching lines...) Expand all Loading... |
199 }; | 199 }; |
200 | 200 |
201 class NonTabTarget : public TargetBase { | 201 class NonTabTarget : public TargetBase { |
202 public: | 202 public: |
203 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) | 203 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
204 : TargetBase(agent_host), | 204 : TargetBase(agent_host), |
205 agent_host_(agent_host) { | 205 agent_host_(agent_host) { |
206 } | 206 } |
207 | 207 |
208 // content::DevToolsTarget implementation: | 208 // content::DevToolsTarget implementation: |
209 virtual std::string GetId() const OVERRIDE { | 209 virtual std::string GetId() const override { |
210 return agent_host_->GetId(); | 210 return agent_host_->GetId(); |
211 } | 211 } |
212 | 212 |
213 virtual std::string GetType() const OVERRIDE { | 213 virtual std::string GetType() const override { |
214 switch (agent_host_->GetType()) { | 214 switch (agent_host_->GetType()) { |
215 case DevToolsAgentHost::TYPE_WEB_CONTENTS: | 215 case DevToolsAgentHost::TYPE_WEB_CONTENTS: |
216 if (TabModelList::begin() == TabModelList::end()) { | 216 if (TabModelList::begin() == TabModelList::end()) { |
217 // If there are no tab models we must be running in ChromeShell. | 217 // If there are no tab models we must be running in ChromeShell. |
218 // Return the 'page' target type for backwards compatibility. | 218 // Return the 'page' target type for backwards compatibility. |
219 return kTargetTypePage; | 219 return kTargetTypePage; |
220 } | 220 } |
221 break; | 221 break; |
222 case DevToolsAgentHost::TYPE_SERVICE_WORKER: | 222 case DevToolsAgentHost::TYPE_SERVICE_WORKER: |
223 return kTargetTypeServiceWorker; | 223 return kTargetTypeServiceWorker; |
224 default: | 224 default: |
225 break; | 225 break; |
226 } | 226 } |
227 return kTargetTypeOther; | 227 return kTargetTypeOther; |
228 } | 228 } |
229 | 229 |
230 virtual bool IsAttached() const OVERRIDE { | 230 virtual bool IsAttached() const override { |
231 return agent_host_->IsAttached(); | 231 return agent_host_->IsAttached(); |
232 } | 232 } |
233 | 233 |
234 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 234 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const override { |
235 return agent_host_; | 235 return agent_host_; |
236 } | 236 } |
237 | 237 |
238 virtual bool Activate() const OVERRIDE { | 238 virtual bool Activate() const override { |
239 return agent_host_->Activate(); | 239 return agent_host_->Activate(); |
240 } | 240 } |
241 | 241 |
242 virtual bool Close() const OVERRIDE { | 242 virtual bool Close() const override { |
243 return agent_host_->Close(); | 243 return agent_host_->Close(); |
244 } | 244 } |
245 | 245 |
246 private: | 246 private: |
247 scoped_refptr<DevToolsAgentHost> agent_host_; | 247 scoped_refptr<DevToolsAgentHost> agent_host_; |
248 }; | 248 }; |
249 | 249 |
250 } // namespace | 250 } // namespace |
251 | 251 |
252 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() | 252 DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 const GURL& url) { | 338 const GURL& url) { |
339 Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 339 Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
340 history::TopSites* top_sites = profile->GetTopSites(); | 340 history::TopSites* top_sites = profile->GetTopSites(); |
341 if (top_sites) { | 341 if (top_sites) { |
342 scoped_refptr<base::RefCountedMemory> data; | 342 scoped_refptr<base::RefCountedMemory> data; |
343 if (top_sites->GetPageThumbnail(url, false, &data)) | 343 if (top_sites->GetPageThumbnail(url, false, &data)) |
344 return std::string(data->front_as<char>(), data->size()); | 344 return std::string(data->front_as<char>(), data->size()); |
345 } | 345 } |
346 return std::string(); | 346 return std::string(); |
347 } | 347 } |
OLD | NEW |