| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 bool DevToolsWindow::IsInspectedBrowserPopup() { | 269 bool DevToolsWindow::IsInspectedBrowserPopup() { |
| 270 Browser* browser = NULL; | 270 Browser* browser = NULL; |
| 271 int tab; | 271 int tab; |
| 272 if (!FindInspectedBrowserAndTabIndex(&browser, &tab)) | 272 if (!FindInspectedBrowserAndTabIndex(&browser, &tab)) |
| 273 return false; | 273 return false; |
| 274 | 274 |
| 275 return (browser->type() & Browser::TYPE_POPUP) != 0; | 275 return (browser->type() & Browser::TYPE_POPUP) != 0; |
| 276 } | 276 } |
| 277 | 277 |
| 278 void DevToolsWindow::SetAttachedWindow() { | 278 void DevToolsWindow::SetAttachedWindow() { |
| 279 tab_contents_->render_view_host()-> | 279 tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( |
| 280 ExecuteJavascriptInWebFrame( | 280 string16(), |
| 281 L"", docked_ ? L"WebInspector.setAttachedWindow(true);" : | 281 docked_ ? ASCIIToUTF16("WebInspector.setAttachedWindow(true);") |
| 282 L"WebInspector.setAttachedWindow(false);"); | 282 : ASCIIToUTF16("WebInspector.setAttachedWindow(false);")); |
| 283 } | 283 } |
| 284 | 284 |
| 285 | 285 |
| 286 void DevToolsWindow::AddDevToolsExtensionsToClient() { | 286 void DevToolsWindow::AddDevToolsExtensionsToClient() { |
| 287 if (inspected_tab_) { | 287 if (inspected_tab_) { |
| 288 FundamentalValue tabId(inspected_tab_->controller().session_id().id()); | 288 FundamentalValue tabId(inspected_tab_->controller().session_id().id()); |
| 289 CallClientFunction(L"WebInspector.setInspectedTabId", tabId); | 289 CallClientFunction(ASCIIToUTF16("WebInspector.setInspectedTabId"), tabId); |
| 290 } | 290 } |
| 291 ListValue results; | 291 ListValue results; |
| 292 const ExtensionService* extension_service = | 292 const ExtensionService* extension_service = |
| 293 tab_contents_->tab_contents()->profile()-> | 293 tab_contents_->tab_contents()->profile()-> |
| 294 GetOriginalProfile()->GetExtensionService(); | 294 GetOriginalProfile()->GetExtensionService(); |
| 295 if (!extension_service) | 295 if (!extension_service) |
| 296 return; | 296 return; |
| 297 | 297 |
| 298 const ExtensionList* extensions = extension_service->extensions(); | 298 const ExtensionList* extensions = extension_service->extensions(); |
| 299 | 299 |
| 300 for (ExtensionList::const_iterator extension = extensions->begin(); | 300 for (ExtensionList::const_iterator extension = extensions->begin(); |
| 301 extension != extensions->end(); ++extension) { | 301 extension != extensions->end(); ++extension) { |
| 302 if ((*extension)->devtools_url().is_empty()) | 302 if ((*extension)->devtools_url().is_empty()) |
| 303 continue; | 303 continue; |
| 304 DictionaryValue* extension_info = new DictionaryValue(); | 304 DictionaryValue* extension_info = new DictionaryValue(); |
| 305 extension_info->Set("startPage", | 305 extension_info->Set("startPage", |
| 306 new StringValue((*extension)->devtools_url().spec())); | 306 new StringValue((*extension)->devtools_url().spec())); |
| 307 results.Append(extension_info); | 307 results.Append(extension_info); |
| 308 } | 308 } |
| 309 CallClientFunction(L"WebInspector.addExtensions", results); | 309 CallClientFunction(ASCIIToUTF16("WebInspector.addExtensions"), results); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void DevToolsWindow::CallClientFunction(const std::wstring& function_name, | 312 void DevToolsWindow::CallClientFunction(const string16& function_name, |
| 313 const Value& arg) { | 313 const Value& arg) { |
| 314 std::string json; | 314 std::string json; |
| 315 base::JSONWriter::Write(&arg, false, &json); | 315 base::JSONWriter::Write(&arg, false, &json); |
| 316 std::wstring javascript = function_name + L"(" + UTF8ToWide(json) + L");"; | 316 string16 javascript = function_name + char16('(') + UTF8ToUTF16(json) + |
| 317 ASCIIToUTF16(");"); |
| 317 tab_contents_->render_view_host()-> | 318 tab_contents_->render_view_host()-> |
| 318 ExecuteJavascriptInWebFrame(L"", javascript); | 319 ExecuteJavascriptInWebFrame(string16(), javascript); |
| 319 } | 320 } |
| 320 | 321 |
| 321 void DevToolsWindow::Observe(NotificationType type, | 322 void DevToolsWindow::Observe(NotificationType type, |
| 322 const NotificationSource& source, | 323 const NotificationSource& source, |
| 323 const NotificationDetails& details) { | 324 const NotificationDetails& details) { |
| 324 if (type == NotificationType::LOAD_STOP && !is_loaded_) { | 325 if (type == NotificationType::LOAD_STOP && !is_loaded_) { |
| 325 SetAttachedWindow(); | 326 SetAttachedWindow(); |
| 326 is_loaded_ = true; | 327 is_loaded_ = true; |
| 327 UpdateTheme(); | 328 UpdateTheme(); |
| 328 DoAction(); | 329 DoAction(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 345 void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) { | 346 void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) { |
| 346 action_on_load_ = action; | 347 action_on_load_ = action; |
| 347 if (is_loaded_) | 348 if (is_loaded_) |
| 348 DoAction(); | 349 DoAction(); |
| 349 } | 350 } |
| 350 | 351 |
| 351 void DevToolsWindow::DoAction() { | 352 void DevToolsWindow::DoAction() { |
| 352 // TODO: these messages should be pushed through the WebKit API instead. | 353 // TODO: these messages should be pushed through the WebKit API instead. |
| 353 switch (action_on_load_) { | 354 switch (action_on_load_) { |
| 354 case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: | 355 case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE: |
| 355 tab_contents_->render_view_host()-> | 356 tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( |
| 356 ExecuteJavascriptInWebFrame(L"", L"WebInspector.showConsole();"); | 357 string16(), ASCIIToUTF16("WebInspector.showConsole();")); |
| 357 break; | 358 break; |
| 358 case DEVTOOLS_TOGGLE_ACTION_INSPECT: | 359 case DEVTOOLS_TOGGLE_ACTION_INSPECT: |
| 359 tab_contents_->render_view_host()-> | 360 tab_contents_->render_view_host()->ExecuteJavascriptInWebFrame( |
| 360 ExecuteJavascriptInWebFrame( | 361 string16(), ASCIIToUTF16("WebInspector.toggleSearchingForNode();")); |
| 361 L"", L"WebInspector.toggleSearchingForNode();"); | |
| 362 case DEVTOOLS_TOGGLE_ACTION_NONE: | 362 case DEVTOOLS_TOGGLE_ACTION_NONE: |
| 363 // Do nothing. | 363 // Do nothing. |
| 364 break; | 364 break; |
| 365 default: | 365 default: |
| 366 NOTREACHED(); | 366 NOTREACHED(); |
| 367 } | 367 } |
| 368 action_on_load_ = DEVTOOLS_TOGGLE_ACTION_NONE; | 368 action_on_load_ = DEVTOOLS_TOGGLE_ACTION_NONE; |
| 369 } | 369 } |
| 370 | 370 |
| 371 std::string SkColorToRGBAString(SkColor color) { | 371 std::string SkColorToRGBAString(SkColor color) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 400 | 400 |
| 401 SkColor color_toolbar = | 401 SkColor color_toolbar = |
| 402 tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); | 402 tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); |
| 403 SkColor color_tab_text = | 403 SkColor color_tab_text = |
| 404 tp->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | 404 tp->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT); |
| 405 std::string command = StringPrintf( | 405 std::string command = StringPrintf( |
| 406 "WebInspector.setToolbarColors(\"%s\", \"%s\")", | 406 "WebInspector.setToolbarColors(\"%s\", \"%s\")", |
| 407 SkColorToRGBAString(color_toolbar).c_str(), | 407 SkColorToRGBAString(color_toolbar).c_str(), |
| 408 SkColorToRGBAString(color_tab_text).c_str()); | 408 SkColorToRGBAString(color_tab_text).c_str()); |
| 409 tab_contents_->render_view_host()-> | 409 tab_contents_->render_view_host()-> |
| 410 ExecuteJavascriptInWebFrame(L"", UTF8ToWide(command)); | 410 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(command)); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void DevToolsWindow::AddNewContents(TabContents* source, | 413 void DevToolsWindow::AddNewContents(TabContents* source, |
| 414 TabContents* new_contents, | 414 TabContents* new_contents, |
| 415 WindowOpenDisposition disposition, | 415 WindowOpenDisposition disposition, |
| 416 const gfx::Rect& initial_pos, | 416 const gfx::Rect& initial_pos, |
| 417 bool user_gesture) { | 417 bool user_gesture) { |
| 418 inspected_tab_->delegate()->AddNewContents(source, | 418 inspected_tab_->delegate()->AddNewContents(source, |
| 419 new_contents, | 419 new_contents, |
| 420 disposition, | 420 disposition, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 437 return false; | 437 return false; |
| 438 } | 438 } |
| 439 | 439 |
| 440 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 440 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 441 if (docked_) { | 441 if (docked_) { |
| 442 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 442 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 443 if (inspected_window) | 443 if (inspected_window) |
| 444 inspected_window->HandleKeyboardEvent(event); | 444 inspected_window->HandleKeyboardEvent(event); |
| 445 } | 445 } |
| 446 } | 446 } |
| OLD | NEW |