| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/debugger/debugger_window.h" | 5 #include "chrome/browser/debugger/debugger_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/json_writer.h" | 9 #include "base/json_writer.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // view hierarchy somewhere. | 98 // view hierarchy somewhere. |
| 99 Profile* profile = BrowserList::GetLastActive()->profile(); | 99 Profile* profile = BrowserList::GetLastActive()->profile(); |
| 100 TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_DEBUGGER, profile, | 100 TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_DEBUGGER, profile, |
| 101 NULL); | 101 NULL); |
| 102 web_contents_ = tc->AsWebContents(); | 102 web_contents_ = tc->AsWebContents(); |
| 103 web_contents_->SetupController(profile); | 103 web_contents_->SetupController(profile); |
| 104 web_contents_->set_delegate(this); | 104 web_contents_->set_delegate(this); |
| 105 web_container_->SetTabContents(web_contents_); | 105 web_container_->SetTabContents(web_contents_); |
| 106 web_contents_->render_view_host()->AllowDOMUIBindings(); | 106 web_contents_->render_view_host()->AllowDOMUIBindings(); |
| 107 | 107 |
| 108 GURL contents("chrome-resource://inspector/debugger.html"); | 108 GURL contents("chrome://inspector/debugger.html"); |
| 109 | |
| 110 web_contents_->controller()->LoadURL(contents, GURL(), | 109 web_contents_->controller()->LoadURL(contents, GURL(), |
| 111 PageTransition::START_PAGE); | 110 PageTransition::START_PAGE); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void DebuggerView::OnShow() { | 113 void DebuggerView::OnShow() { |
| 115 web_contents_->Focus(); | 114 web_contents_->Focus(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void DebuggerView::OnClose() { | 117 void DebuggerView::OnClose() { |
| 119 web_container_->SetTabContents(NULL); | 118 web_container_->SetTabContents(NULL); |
| 120 web_contents_->CloseContents(); | 119 web_contents_->CloseContents(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void DebuggerView::OpenURLFromTab(TabContents* source, | 122 void DebuggerView::OpenURLFromTab(TabContents* source, |
| 124 const GURL& url, | 123 const GURL& url, |
| 125 const GURL& referrer, | 124 const GURL& referrer, |
| 126 WindowOpenDisposition disposition, | 125 WindowOpenDisposition disposition, |
| 127 PageTransition::Type transition) { | 126 PageTransition::Type transition) { |
| 128 BrowserList::GetLastActive()->OpenURL(url, referrer, disposition, | 127 BrowserList::GetLastActive()->OpenURL(url, referrer, disposition, |
| 129 transition); | 128 transition); |
| 130 } | 129 } |
| 131 | 130 |
| 132 | 131 |
| 133 void DebuggerView::SendEventToPage(const std::wstring& name, | 132 void DebuggerView::SendEventToPage(const std::wstring& name, |
| 134 Value* body) { | 133 Value* body) { |
| 135 DictionaryValue msg; | 134 DictionaryValue msg; |
| 136 msg.SetString(L"type", L"event"); | 135 msg.SetString(L"type", L"event"); |
| 137 msg.SetString(L"event", name); | 136 msg.SetString(L"event", name); |
| 138 msg.Set(L"body", body); | 137 msg.Set(L"body", body); |
| 139 | 138 |
| 140 std::string json; | 139 std::string json; |
| 141 JSONWriter::Write(&msg, false, &json); | 140 JSONWriter::Write(&msg, false, &json); |
| 142 | 141 |
| 143 const std::string js = | 142 const std::string js = |
| 144 StringPrintf("DebuggerIPC.onMessageReceived(%s)", json.c_str()); | 143 StringPrintf("DebuggerIPC.onMessageReceived(%s)", json.c_str()); |
| 145 if (output_ready_) { | 144 if (output_ready_) { |
| 146 ExecuteJavascript(js); | 145 ExecuteJavascript(js); |
| 147 } else { | 146 } else { |
| 148 pending_events_.push_back(js); | 147 pending_events_.push_back(js); |
| 149 } | 148 } |
| 150 } | 149 } |
| 151 | 150 |
| 152 void DebuggerView::ExecuteJavascript(const std::string& js) { | 151 void DebuggerView::ExecuteJavascript(const std::string& js) { |
| 153 web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(L"", | 152 web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(L"", |
| 154 UTF8ToWide(js)); | 153 UTF8ToWide(js)); |
| 155 } | 154 } |
| 156 | 155 |
| 157 void DebuggerView::LoadingStateChanged(TabContents* source) { | 156 void DebuggerView::LoadingStateChanged(TabContents* source) { |
| 158 if (!source->is_loading()) | 157 if (!source->is_loading()) |
| 159 SetOutputViewReady(); | 158 SetOutputViewReady(); |
| 160 } | 159 } |
| 161 | 160 |
| OLD | NEW |