Skip to content

Commit 7213884

Browse files
committed
Disable logging if the chrome://inspect page web view is purged.
The system may purge the web view associated with the chrome://inspect page if it is left with logging enabled and many other tabs are used. Since the web view is gone, a page reload must occur when the user navigates back to the tab. The reload will cause all logs to be cleared from the chrome://inspect page and will reset the button back to "Start Logging". Turning off logging in InspectDOMHandler ensures that the state matches what the user will see when they navigate back to the chrome://inspect tab. Bug: 920823 Change-Id: I852d5a264f2d11424e8183fe1aeffb0299572537 Reviewed-on: https://chromium-review.googlesource.com/c/1435035 Commit-Queue: Mike Dougherty <[email protected]> Reviewed-by: Eugene But <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#626196}(cherry picked from commit a1fa214) Reviewed-on: https://chromium-review.googlesource.com/c/1444138 Reviewed-by: Mike Dougherty <[email protected]> Cr-Commit-Position: refs/branch-heads/3683@{#48} Cr-Branched-From: e510299-refs/heads/master@{#625896}
1 parent a4572ae commit 7213884

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ios/chrome/browser/ui/webui/inspect/inspect_ui.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ void SetDelegateForWebStatesInTabModel(
185185
web::WebState* web_state,
186186
web::WebFrame* sender_frame,
187187
const JavaScriptConsoleMessage& message) {
188+
web::WebFrame* inspect_ui_main_frame =
189+
web::GetMainWebFrame(web_ui()->GetWebState());
190+
if (!inspect_ui_main_frame) {
191+
// Disable logging and drop this message because the main frame no longer
192+
// exists.
193+
SetLoggingEnabled(false);
194+
return;
195+
}
196+
188197
std::vector<base::Value> params;
189198
web::WebFrame* main_web_frame = web::GetMainWebFrame(web_state);
190199
params.push_back(base::Value(main_web_frame->GetFrameId()));
@@ -193,8 +202,8 @@ void SetDelegateForWebStatesInTabModel(
193202
params.push_back(base::Value(message.level));
194203
params.push_back(message.message->Clone());
195204

196-
web::GetMainWebFrame(web_ui()->GetWebState())
197-
->CallJavaScriptFunction("inspectWebUI.logMessageReceived", params);
205+
inspect_ui_main_frame->CallJavaScriptFunction(
206+
"inspectWebUI.logMessageReceived", params);
198207
}
199208

200209
void InspectDOMHandler::SetDelegateForWebStatesInTabModel(

0 commit comments

Comments
 (0)