<commit_before>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/devtools/protocol/color_picker.h"

#include "base/bind.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/common/cursors/webcursor.h"
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/gfx/geometry/size_conversions.h"

namespace content {
namespace devtools {
namespace page {

ColorPicker::ColorPicker(ColorPickedCallback callback)
    : callback_(callback),
      enabled_(false),
      last_cursor_x_(-1),
      last_cursor_y_(-1),
      host_(nullptr),
      weak_factory_(this) {
  mouse_event_callback_ = base::Bind(
      &ColorPicker::HandleMouseEvent,
      base::Unretained(this));
}

ColorPicker::~ColorPicker() {
}

void ColorPicker::SetRenderWidgetHost(RenderWidgetHostImpl* host) {
  if (host_ == host)
    return;

  if (host_)
    host_->RemoveMouseEventCallback(mouse_event_callback_);
  ResetFrame();
  host_ = host;
  if (enabled_ && host)
    host->AddMouseEventCallback(mouse_event_callback_);
}

void ColorPicker::SetEnabled(bool enabled) {
  if (enabled_ == enabled)
    return;

  enabled_ = enabled;
  if (!host_)
    return;

  if (enabled) {
    host_->AddMouseEventCallback(mouse_event_callback_);
    UpdateFrame();
  } else {
    host_->RemoveMouseEventCallback(mouse_event_callback_);
    ResetFrame();

    WebCursor pointer_cursor;
    WebCursor::CursorInfo cursor_info;
    cursor_info.type = blink::WebCursorInfo::TypePointer;
    pointer_cursor.InitFromCursorInfo(cursor_info);
    host_->SetCursor(pointer_cursor);
  }
}
<commit_msg>[DevTools] Fix crash in ColorPicker::SetRenderWidgetHost.<commit_after>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/devtools/protocol/color_picker.h"

#include "base/bind.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/common/cursors/webcursor.h"
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/gfx/geometry/size_conversions.h"

namespace content {
namespace devtools {
namespace page {

ColorPicker::ColorPicker(ColorPickedCallback callback)
    : callback_(callback),
      enabled_(false),
      last_cursor_x_(-1),
      last_cursor_y_(-1),
      host_(nullptr),
      weak_factory_(this) {
  mouse_event_callback_ = base::Bind(
      &ColorPicker::HandleMouseEvent,
      base::Unretained(this));
}

ColorPicker::~ColorPicker() {
}

void ColorPicker::SetRenderWidgetHost(RenderWidgetHostImpl* host) {
  if (host_ == host)
    return;

  if (enabled_ && host_)
    host_->RemoveMouseEventCallback(mouse_event_callback_);
  ResetFrame();
  host_ = host;
  if (enabled_ && host)
    host->AddMouseEventCallback(mouse_event_callback_);
}

void ColorPicker::SetEnabled(bool enabled) {
  if (enabled_ == enabled)
    return;

  enabled_ = enabled;
  if (!host_)
    return;

  if (enabled) {
    host_->AddMouseEventCallback(mouse_event_callback_);
    UpdateFrame();
  } else {
    host_->RemoveMouseEventCallback(mouse_event_callback_);
    ResetFrame();

    WebCursor pointer_cursor;
    WebCursor::CursorInfo cursor_info;
    cursor_info.type = blink::WebCursorInfo::TypePointer;
    pointer_cursor.InitFromCursorInfo(cursor_info);
    host_->SetCursor(pointer_cursor);
  }
}

{'fraction_non_alphanumeric': 0.1153462879920279, 'fraction_numerical': 0.0029895366218236174, 'mean_word_length': 4.921828908554573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3514503', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1257, 'n_words': 227}